%3CLINGO-SUB%20id%3D%22lingo-sub-1047929%22%20slang%3D%22en-US%22%3EMine%20Knowledge%20of%20File%20Names%20and%20Paths%20with%20a%20Python%20Custom%20Skill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1047929%22%20slang%3D%22en-US%22%3E%3CH1%20id%3D%22toc-hId-355767189%22%20id%3D%22toc-hId-355767189%22%3EMine%20Knowledge%20on%20File%20Names%20and%20Paths%20with%20a%20Python%20Custom%20Skill%3C%2FH1%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAzure%20Cognitive%20Search%20is%20the%20Microsoft%20product%20for%20Knowledge%20Mining%2C%20a%20process%20to%20extract%20information%20from%20unstructured%20or%20semi-structured%20data.%20However%2C%20extracting%20knowledge%20of%20file%20names%20or%20paths%20is%20not%20trivial.%20In%20this%20article%20you%20will%20learn%20how%20to%20do%20it%20using%20Azure%20Functions%20for%20Python%2C%20that%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fannouncing-the-general-availability-of-python-support-in-azure-functions%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewent%20to%20GA%3C%2FA%3E%20on%20August%2019%3CSUP%3Eth%3C%2FSUP%3E%2C%202019.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1046328663%22%20id%3D%22toc-hId-1046328663%22%3EWhy%20mine%20knowledge%20of%20file%20names%20and%20paths%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20lack%20of%20metadata%20is%20a%20common%20scenario%20in%20all%20companies%20in%20the%20world%2C%20usually%20people%20don%E2%80%99t%20have%20time%20or%20discipline%20to%20add%20tags%20or%20comments%20to%20their%20documents%2C%20leaving%20the%20file%20name%20and%20its%20path%20the%20only%20information%20available%20for%20searches.%20This%20problem%20is%20addressed%20with%20Knowledge%20Mining%2C%20metadata%20will%20be%20created%20for%20you.%20Azure%20Cognitive%20Search%20uses%20AI%20to%20extract%20insights%20from%20your%20files%20content.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20look%20at%20the%20image%20below.%20%26nbsp%3BWith%20the%20file%20name%20and%20its%20path%20have%20we%20already%20discovered%20the%20name%20of%20the%20project%2C%20the%20year%2C%20the%20type%20of%20the%20file%2C%20its%20title%2C%20among%20other%20things.%20It%20is%20very%20common%20to%20see%20dates%2C%20hours%2C%20names%2C%20and%20locations%20in%20the%20names%20and%20paths%20of%20the%20files.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F160025iC1699AB2A05D20BC%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFigure%201%3A%20Lack%20and%20valuable%20metadata%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--761125800%22%20id%3D%22toc-hId--761125800%22%3EWhy%20do%20we%20need%20a%20Custom%20Skill%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-skill-textmerger%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EText%20Merge%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eskill%20consolidates%20text%20from%20documents%20%3CSTRONG%3Econtent%3C%2FSTRONG%3E%26nbsp%3Bwith%20images%20%3CSTRONG%3EOCR%20Text%3C%2FSTRONG%3E%20into%20a%20single%20annotation%20within%20your%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-concept-intro%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Cognitive%20Search%20Enrichment%20Pipeline%3C%2FA%3E%20.%26nbsp%3B%3CSPAN%3EA%20common%20scenario%20for%20using%20Text%20Merge%20is%20to%20merge%20the%20textual%20representation%20of%20images%20(text%20from%20an%20OCR%20skill%2C%20or%20the%20caption%20of%20an%20image)%20into%20the%20content%20field%20of%20a%20document.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EBy%20doing%20this%2C%20you%20will%20optimize%20insights%20extraction%2C%20index%20storage%2C%20and%20user%20interface%20development.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20you%20can't%20use%20the%20%3CSTRONG%3E%3CEM%3EMerge%20Skill%3C%2FEM%3E%3C%2FSTRONG%3E%26nbsp%3Bfor%20file%20names%20or%20paths%2C%20because%20on%20the%20required%26nbsp%3B%3CSTRONG%3Eoffsets%3C%2FSTRONG%3E%20property.%20It%20is%20one%20of%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-skill-ocr%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EOCR%20Skill%3C%2FA%3E%26nbsp%3Boutputs%20and%20you%20don't%20have%20this%20information%20for%20physical%20properties%20of%20the%20documents.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat's%20why%20you%20need%20to%26nbsp%3Bleverage%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-create-custom-skill-example%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECustom%20Skills%3C%2FA%3E%20flexibility%20to%26nbsp%3Bmerge%20properties%20like%20%3CSTRONG%3Emetadata_storage_name%3C%2FSTRONG%3E%20and%20%3CSTRONG%3Emetadata_storage_path%3C%2FSTRONG%3E%20with%20the%20document%20%3CSTRONG%3Econtent%3C%2FSTRONG%3E.%26nbsp%3BThis%20article%20code%20uses%20the%20file%20name%2C%20but%20it%20would%20work%20fine%20with%20file%E2%80%99s%20dates%2C%20path%2C%20author%2C%20etc.%20It%20will%20also%20work%20with%26nbsp%3Bother%20skills%20outputs%2C%20like%20image%20analysis.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1726387033%22%20id%3D%22toc-hId-1726387033%22%3ECode%20and%20Deployment%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20code%20of%20the%20solution%20suggested%20is%20available%20is%20in%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FRodrigossz%2FPyhton-Custom-Skills-Toolkit%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20%3C%2FA%3EGitHub%20repo%20and%20here%20are%20some%20important%20guidelines%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIf%20you%20are%20curious%20to%20know%20why%20I%20am%20using%20Python%20and%20Azure%20Functions%2C%20check%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAI-Customer-Engineering-Team%2FUsing-Azure-Functions-for-Python-to-create-a-Cognitive-Search%2Fba-p%2F850106%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ethis%3C%2FA%3E%20previous%20blog%20post.%3C%2FLI%3E%0A%3CLI%3EStart%20with%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-create-first-function-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%3C%2FA%3E%20tutorial%2C%20to%20create%20and%20deploy%20your%20environment%3C%2FLI%3E%0A%3CLI%3EThe%20recommended%20Python%20version%20is%203.7.4%2C%20meaning%20that%20if%20you%20use%20Anaconda%20actual%20version%2C%20November%202019%2C%20you%20are%20free%20of%20any%20version%20preoccupation.%20If%20you%20are%20in%20the%20future%20and%20have%20a%20newer%20version%2C%20you%20can%20use%20conda%20to%20create%20the%20requested%20environment%3A%20%3CSTRONG%3E%3CEM%3Econda%20create%20-n%20your-env-name%20python%3D3.6%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EWhen%20you%20create%20a%20local%20project%2C%20with%20the%20command%20%3CSTRONG%3E%3CEM%3Efunc%20init%20your-project-name%3C%2FEM%3E%3C%2FSTRONG%3E%2C%20all%20necessary%20files%20are%20created%20within%20your%20project%20folder.%20Including%20one%20file%20for%20requirements%20(like%20an%20yml%20file)%20and%20%3CSTRONG%3E%3CEM%3Epy%2C%20%3C%2FEM%3E%3C%2FSTRONG%3Ethat%20is%20a%20template%20for%20your%20code.%20At%20the%20end%20of%20the%20day%2C%20Azure%20Functions%20will%20simulate%20conda%20with%20the%20requirements%20you%20specify%20into%20the%20%3CSTRONG%3E%3CEM%3Erequirements.txt%3C%2FEM%3E%3C%2FSTRONG%3E%20file.%3C%2FLI%3E%0A%3CLI%3EPlease%20note%20that%20you%20need%20to%20use%20%3CSTRONG%3E%3CEM%3Emimetype%3D%E2%80%9Dapplication%2Fjson%E2%80%9D%20%3C%2FEM%3E%3C%2FSTRONG%3Efor%20your%20http-response%2C%20since%20the%20Cognitive%20Search%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-custom-skill-interface%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Einterface%3C%2FA%3E%20expects%20a%20json%20file%20as%20a%20return.%3C%2FLI%3E%0A%3CLI%3EYou%20will%20need%20to%20pip%20install%20%3CSTRONG%3E%3CEM%3Efunctions%3C%2FEM%3E%3C%2FSTRONG%3E%20from%20your%20command%20line%20interface.%3C%2FLI%3E%0A%3CLI%3EThe%20code%20removes%20special%20characters.%20Please%20check%20your%20business%20requirements%20and%20the%20lessons%20learned%20below%20to%20define%20what%20transformations%20you%20need.%3C%2FLI%3E%0A%3CLI%3EAs%20you%20can%20see%20in%20the%20image%20below%2C%20the%20%3CSTRONG%3E%3CEM%3Emetadata_storage_name%3C%2FEM%3E%3C%2FSTRONG%3E%20and%20the%20%3CSTRONG%3E%3CEM%3Econtent%3C%2FEM%3E%3C%2FSTRONG%3E%20are%20the%20input%20strings%20for%20the%20skill.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F160024i2461A68A2757D3A3%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFigure%202%3A%20How%20to%20connect%20the%20Custom%20Skill%20to%20your%20Skillset%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--81067430%22%20id%3D%22toc-hId--81067430%22%3EKey%20Lessons%20Learned%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20a%20list%20of%20good%20practices%20from%20our%20experience%20when%20creating%20this%20solution%20for%20a%20client%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWhen%20possible%2C%20leverage%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-reference-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eglobal%20cached%20data%3C%2FA%3E%20for%20the%20reference%20data.%20It%20is%20not%20guaranteed%20that%20the%20state%20of%20your%20app%20will%20be%20preserved%20for%20future%20executions.%20However%2C%20the%20Azure%20Functions%20runtime%20often%20reuses%20the%20same%20process%20for%20multiple%20executions%20of%20the%20same%20app.%20In%20order%20to%20cache%20the%20results%20of%20an%20expensive%20computation%2C%20declare%20it%20as%20a%20global%20variable.%3C%2FLI%3E%0A%3CLI%3EAlways%20prepare%20your%20code%20to%20deal%20with%20empty%20result%20sets%2C%20if%20a%20term%20is%20filtered%2C%20the%20result%20is%20empty%20string%20to%20be%20added%20to%20the%20result%20set.%3C%2FLI%3E%0A%3CLI%3EVS%20Code%20and%20Postman%20will%20work%20great%20for%20local%20debugging%2C%20you%20just%20need%20to%20save%20the%20new%20version%20of%20your%20python%20code%20and%20the%20changes%20are%20effective%20immediately%2C%20not%20requiring%20you%20to%20restart%20the%20service.%20This%20dynamic%20process%20allows%20you%20to%20quickly%20change%20your%20code%20and%20see%20the%20results.%3C%2FLI%3E%0A%3CLI%3EIn%20your%20code%2C%20use%20%3CSTRONG%3E%3CEM%3Edumps%20%3C%2FEM%3E%3C%2FSTRONG%3Eon%20your%20output%20variable%20to%20validate%20what%20your%20skill%20returns%20to%20Cognitive%20Search.%20This%20will%20give%20you%20the%20opportunity%20to%20fix%20the%20layout%20in%20case%20of%20error.%3C%2FLI%3E%0A%3CLI%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fservices%2Fcognitive-services%2Ftext-analytics%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EText%20Analytics%20API%3C%2FA%3E%2C%20that%20is%20used%20under%20the%20hood%2C%20will%20remove%20characters%20like%20%22_%22%20or%20%22-%22.%20But%20if%20you%20submit%20%3CSTRONG%3E%3CEM%3E%22vacation_summer_in_Brazil_01.jpg%22%3C%2FEM%3E%3C%2FSTRONG%3E%2C%20you%20will%20get%20%22Brazil%22%20as%20an%20entity%20of%20the%20location%20type%2C%20and%20nothing%20else.%20However%2C%20if%20you%20submit%20%3CSTRONG%3E%3CEM%3E%22vacation%20summer%20in%20Brazil%2001%20jpg%22%3C%2FEM%3E%3C%2FSTRONG%3E%2C%20you%20will%20get%3A%26nbsp%3B%3CUL%3E%0A%3CLI%3EKey%20Phrases%3A%20vacation%20summer%2C%20Brazil%2C%20jpg%3C%2FLI%3E%0A%3CLI%3EEntities%3A%20Brazil%20(location)%2C%20summer%20(datetime-dateRange)%2C%2001%20(quantity-number).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--1888521893%22%20id%3D%22toc-hId--1888521893%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-598990940%22%20id%3D%22toc-hId-598990940%22%3EIs%20there%20an%20alternative%20for%20a%20Custom%20Skill%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYes%2C%20there%20is.%20Also%20not%20supported%20or%20documented%2C%20and%20only%20using%20built%20in%20skills.%20I%20%3CSTRONG%3Edon%E2%80%99t%3C%2FSTRONG%3E%20recommend%20this%20alternative%20since%20I%20have%20never%20tested%20it%20and%20much%20more%20steps%20are%20required%20to%20achieve%20a%20similar%20objective.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3EOffsets%3C%2FEM%3E%3C%2FSTRONG%3E%20and%20%3CSTRONG%3E%3CEM%3EitemsToInsert%3C%2FEM%3E%3C%2FSTRONG%3E%20are%20Merge%20Skill%20properties%20that%20expect%20arrays.%20You%20can%20submit%20the%20file%20name%2C%20or%20any%20other%20string%2C%20to%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-skill-textsplit%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESplit%20Skil.%3C%2FA%3E%20It%20will%20split%20the%20content%20into%20an%20array%20of%202%20positions%2C%20and%20then%20need%20to%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-skill-conditional%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EConditional%20Skill%3C%2FA%3E%20to%20create%20an%20array%20with%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsearch%2Fcognitive-search-skill-conditional%23sample-skill-definition-4-data-transformation-on-a-single-field%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehard%20coded%20values%3C%2FA%3E.%20The%20last%20step%20is%20to%20run%20the%20%3CSTRONG%3E%3CEM%3EMerge%20Skill%3C%2FEM%3E%3C%2FSTRONG%3E%20to%20merge%20the%20contents%20in%20the%20array%20to%20the%20rest%20of%20the%20content.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1208463523%22%20id%3D%22toc-hId--1208463523%22%3EPowerSkills%20%E2%80%93%20Azure%20Search%20Team%20Official%20Custom%20Skills%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20Azure%20Search%20click-to-deploy%20C%23%20Custom%20skills%2C%20created%20by%20the%20Azure%20Search%20Team%2C%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2Fazure-search-power-skills%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Search%20Power%20Skills%3C%2FA%3E.%20Previous%20C%23%20knowledge%20or%20software%20installations%20aren't%20required%2C%20they%20have%20the%20%22one%20click%20deployment%22%20concept.%20There%20are%20Custom%20Skills%20for%20Lookup%2C%20distinct%20(duplicates%20removal)%2C%20and%20more.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1279049310%22%20id%3D%22toc-hId-1279049310%22%3ERelated%20Links%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUseful%20links%20for%20those%20who%20want%20to%20know%20more%20about%20Knowledge%20Mining%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EPython%20Custom%20Skills%20Toolkit%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FRodrigossz%2FPyhton-Custom-Skills-Toolkit%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EKnowledge%20Mining%20Accelerator%20-%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fkma%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eaka.ms%2Fkma%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EKnowledge%20Mining%20Bootcamp%20%E2%80%93%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fkmb%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eaka.ms%2Fkmb%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EKnowledge%20Mining%20posts%20%E2%80%93%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAI-Customer-Engineering-Team%2Fbg-p%2FAICustomerEngineeringTeam%2Flabel-name%2FKnowledge%2520Mining%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Eaka.ms%2FACE-Blog%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--528405153%22%20id%3D%22toc-hId--528405153%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--662089877%22%20id%3D%22toc-hId--662089877%22%3EConclusion%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20post%20helps%20you%20to%20create%20Python%20Custom%20Skill%2C%20for%20Azure%20Cognitive%20Search%2C%20based%20on%20Azure%20Functions%20for%20Python.%20It%20merges%202%20strings%20in%20a%20third%20one.%20Typical%20usage%20is%20when%20you%20want%20to%20concatenate%2C%20within%20an%20Enrichment%20Pipeline%2C%20the%20file%20name%20or%20path%20with%20the%20content.%20This%20skill%20is%20indicated%20for%20scenarios%20when%20the%20file%20name%20or%20path%20have%20dates%2C%20organizations%2C%20names%2C%20or%20key%20phrases.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1047929%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20mine%20knowledge%20of%20file%20names%20and%20paths%2C%20and%20why%20do%20you%20need%20a%20Python%20custom%20skill%20to%20do%20it.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1047929%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Cognitive%20Search%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Search%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzureAI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECognitive%20Services%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EE2E%20Solutions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EKnowledge%20Mining%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epython%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Mine Knowledge on File Names and Paths with a Python Custom Skill

 

Azure Cognitive Search is the Microsoft product for Knowledge Mining, a process to extract information from unstructured or semi-structured data. However, extracting knowledge of file names or paths is not trivial. In this article you will learn how to do it using Azure Functions for Python, that went to GA on August 19th, 2019.

 

Why mine knowledge of file names and paths?

 

The lack of metadata is a common scenario in all companies in the world, usually people don’t have time or discipline to add tags or comments to their documents, leaving the file name and its path the only information available for searches. This problem is addressed with Knowledge Mining, metadata will be created for you. Azure Cognitive Search uses AI to extract insights from your files content.

 

But look at the image below.  With the file name and its path have we already discovered the name of the project, the year, the type of the file, its title, among other things. It is very common to see dates, hours, names, and locations in the names and paths of the files.

 

clipboard_image_0.png

Figure 1: Lack and valuable metadata

 

Why do we need a Custom Skill?

 

The Text Merge skill consolidates text from documents content with images OCR Text into a single annotation within your Azure Cognitive Search Enrichment PipelineA common scenario for using Text Merge is to merge the textual representation of images (text from an OCR skill, or the caption of an image) into the content field of a document. By doing this, you will optimize insights extraction, index storage, and user interface development.

 

But you can't use the Merge Skill for file names or paths, because on the required offsets property. It is one of the OCR Skill outputs and you don't have this information for physical properties of the documents.

 

That's why you need to leverage Custom Skills flexibility to merge properties like metadata_storage_name and metadata_storage_path with the document content. This article code uses the file name, but it would work fine with file’s dates, path, author, etc. It will also work with other skills outputs, like image analysis.

 

Code and Deployment

 

The code of the solution suggested is available is in this GitHub repo and here are some important guidelines:

  • If you are curious to know why I am using Python and Azure Functions, check this previous blog post.
  • Start with this tutorial, to create and deploy your environment
  • The recommended Python version is 3.7.4, meaning that if you use Anaconda actual version, November 2019, you are free of any version preoccupation. If you are in the future and have a newer version, you can use conda to create the requested environment: conda create -n your-env-name python=3.6
  • When you create a local project, with the command func init your-project-name, all necessary files are created within your project folder. Including one file for requirements (like an yml file) and py, that is a template for your code. At the end of the day, Azure Functions will simulate conda with the requirements you specify into the requirements.txt file.
  • Please note that you need to use mimetype=”application/json” for your http-response, since the Cognitive Search interface expects a json file as a return.
  • You will need to pip install functions from your command line interface.
  • The code removes special characters. Please check your business requirements and the lessons learned below to define what transformations you need.
  • As you can see in the image below, the metadata_storage_name and the content are the input strings for the skill.

clipboard_image_1.png

Figure 2: How to connect the Custom Skill to your Skillset

 

Key Lessons Learned

 

Here is a list of good practices from our experience when creating this solution for a client:

  • When possible, leverage global cached data for the reference data. It is not guaranteed that the state of your app will be preserved for future executions. However, the Azure Functions runtime often reuses the same process for multiple executions of the same app. In order to cache the results of an expensive computation, declare it as a global variable.
  • Always prepare your code to deal with empty result sets, if a term is filtered, the result is empty string to be added to the result set.
  • VS Code and Postman will work great for local debugging, you just need to save the new version of your python code and the changes are effective immediately, not requiring you to restart the service. This dynamic process allows you to quickly change your code and see the results.
  • In your code, use dumps on your output variable to validate what your skill returns to Cognitive Search. This will give you the opportunity to fix the layout in case of error.
  • The Text Analytics API, that is used under the hood, will remove characters like "_" or "-". But if you submit "vacation_summer_in_Brazil_01.jpg", you will get "Brazil" as an entity of the location type, and nothing else. However, if you submit "vacation summer in Brazil 01 jpg", you will get: 
    • Key Phrases: vacation summer, Brazil, jpg
    • Entities: Brazil (location), summer (datetime-dateRange), 01 (quantity-number).

 

Is there an alternative for a Custom Skill?

 

Yes, there is. Also not supported or documented, and only using built in skills. I don’t recommend this alternative since I have never tested it and much more steps are required to achieve a similar objective.

Offsets and itemsToInsert are Merge Skill properties that expect arrays. You can submit the file name, or any other string, to the Split Skil. It will split the content into an array of 2 positions, and then need to use the Conditional Skill to create an array with the hard coded values. The last step is to run the Merge Skill to merge the contents in the array to the rest of the content.

 

PowerSkills – Azure Search Team Official Custom Skills

 

For Azure Search click-to-deploy C# Custom skills, created by the Azure Search Team, use the Azure Search Power Skills. Previous C# knowledge or software installations aren't required, they have the "one click deployment" concept. There are Custom Skills for Lookup, distinct (duplicates removal), and more.

 

Related Links

 

Useful links for those who want to know more about Knowledge Mining:

 

Conclusion

 

This post helps you to create Python Custom Skill, for Azure Cognitive Search, based on Azure Functions for Python. It merges 2 strings in a third one. Typical usage is when you want to concatenate, within an Enrichment Pipeline, the file name or path with the content. This skill is indicated for scenarios when the file name or path have dates, organizations, names, or key phrases.