find-keyword-xtvu 5.7.3

Creator: bradpython12

Last updated:

Add to Cart

Description:

findkeywordxtvu 5.7.3

English version
The find_keyword_xtvu Python package facilitates the search for keywords across PDF, DOCX, ODT, and RTF files, enabling the extraction of sentences that contain these keywords. It also offers support for multiple languages and can run on multicore CPUs.
đŸ”„ Recent Updates
✹ What's New in Version 5.7.3

❗ Important Modification in the output of the frequency table: This update changes the way the results in the frequency table are presented. Now, instead of each contingency table from a subfolder being recorded on a separate sheet, all of them will be placed on a single sheet to facilitate the interpretation of the results.

✹ What's New in Version 5.7.2

❗ Important Modification in Cache File Generation Using cache_folder_path argument: This update improves the handling of large document collections by changing the principle of cache file generation. Unlike version 5.7, where a single JSON cache file was used for all documents, the function now creates individual cache files for each subfolder. This enhances performance and organization, especially when dealing with large quantities of documents.

✹ What's New in Version 5.7

🆕 Enhanced PDF Processing with the new cache_file_path argument: This update introduces a powerful feature that optimizes document processing through JSON-based caching. When a cache_file_path is provided, the function first checks whether the extracted text data for the file is already stored in the JSON cache. If the data is found, the function skips the extraction process, significantly speeding up the analysis. If not, the function will proceed with the extraction, save the resulting data to the JSON cache, and ensure that future analyses of the same file are much faster.

Installation
You can install this package via pip:
pip install find-keyword-xtvu==<latest_version_on_PyPi>

Directory Structure
The directory organization containing the .py code and documents can be structured as follows:
/Parent Folder
│
├── script_principal.py # The main Python script
│
├── fichiers_entre # Folder containing subfolders of PDF files
│ ├── files1 # Subfolder containing input .pdf, .docx, .otd, and .rtf files
│ ├── files2
│ ├── files3
│ ...
└── resultats # Folder containing the results

Usage


Place the files in the input directory:

Place the PDF, DOCX, ODT, or RTF files you want to analyze into the subfolders within the fichiers_entree directory. By default, you can organize them in a single subfolder (e.g., files1) or in multiple subfolders (files2, files3, etc.), depending on your needs.



Define the keywords:

Open the script_principal.py script and modify the KEYWORDS list to include the keywords you want to search for in the files.



Run the script:

Run the script_principal.py script in an IDE like Visual Studio Code.



The script_principal.py file uses the find_keyword_xtvu package and can be organized as follows:
from find_keyword_xtvu import find_keyword_xtvu
if __name__ == "__main__":
find_keyword_xtvu(
prefixe_langue = 'fr',
threads_rest = None,
nb_phrases_avant = 10,
nb_phrases_apres = 10,
keywords = [["",""],""],
exact_match = True,
taille = 20,
timeout = 200,
result_keyword_table_name = "",
freque_document_keyword_table_name = "",
fusion_keyword_before_after = False,
tesseract_cmd = "/usr/local/bin/tesseract",
use_tesseract = False,
use_full_tesseract = False,
lang_OCR_tesseract = 'fra',
input_path = "/path/to/fichiers_entre",
output_path = "/path/to/resultats",
cache_folder_path = "/path/to/cache_folder"
)

Arguments

prefixe_langue: Language prefix to specify the language model to use (default value: 'fr'). To know the supported languages and their prefixes, see the SpaCy documentation. If you provide an unsupported prefix, or if you want to use the multilingual model, specify the multi argument. In either case, the multilingual model xx_ent_wiki_sm will be used. Learn more about this model here.
threads_rest: Number of threads reserved for other tasks. If left unspecified, the library will default to using half of the available cores.
nb_phrases_avant: Number of sentences to include before the keyword (default value: 10).
nb_phrases_apres: Number of sentences to include after the keyword (default value: 10).
keywords: List of keywords to search for. To group multiple keywords that should be treated the same way, use a list format like ["keyword1", "keyword2"] (for example, ["local", "nearby"] to treat them as synonyms). If you want to treat keywords separately, simply place each keyword as a standalone string, like "keyword". For example, if we structure it like this [["local", "nearby"], "school", "library", "park"], it means that "local" and "nearby" will be treated as synonyms, while "school", "library", and "park" will each be treated as distinct keywords.
exact_match: This boolean parameter determines whether the keyword search should match the exact word as provided. If set to True, only exact matches of the keyword will be considered during text extraction. If set to False, the search will be based on the lemma form of the keyword, allowing for more flexible matching by capturing different variations of the word (e.g., "run," "running," "ran"). To learn more about lemma forms, see this page.
taille: Maximum file size to process in megabytes (default value: 20 MB).
timeout: Maximum time for processing a page in seconds (default value: 200).
result_keyword_table_name: Name of the table for keyword results. If this field is empty, a default name for this table will be res.
freque_document_keyword_table_name: Name of the table for the results of the contingency tables of keyword frequency in each file folder. If this field is empty, the default name for this table will be freque_document_keyword.
fusion_keyword_before_after: This boolean parameter controls whether the function should avoid including redundant phrases when a keyword appears multiple times within close proximity in the text. When set to True, the function ensures that phrases surrounding a keyword are only extracted once, even if they overlap with the phrases surrounding another occurrence of the same keyword. This prevents the repetition of phrases in the final output, leading to a more concise result. If set to False, the function will extract all phrases surrounding each occurrence of the keyword, which may lead to redundancy if the keyword appears frequently in the text. (default value: False)
tesseract_cmd: Path to the Tesseract executable (default value: "/usr/local/bin/tesseract").
use_tesseract: This boolean parameter controls whether to use Tesseract OCR for processing images within the documents. When set to True, the function will extract text from images using Tesseract OCR, which is useful if the documents contain scanned images or embedded pictures with text. Ensure that tesseract_cmd is correctly set to the path of the Tesseract executable. If set to False, the function will ignore images in the documents and only process the text that is directly extractable without OCR. This can be faster and avoids the need to install Tesseract. (default value: False)
use_full_tesseract: This boolean parameter controls whether to apply Tesseract OCR to the entire page of the document. When enabled, the entire page is converted into an image, and Tesseract is used to extract text from the entire image. This results in more accurate text extraction and preserves the document's structure, but it is more computationally intensive. If only use_tesseract is enabled without use_full_tesseract, Tesseract will only extract text from specific images on the page, rather than the entire page. (default value: False)
lang_OCR_tesseract: Language code used by Tesseract OCR to identify the language of the text to be extracted from images. You can specify other language codes supported by Tesseract depending on the language of the text in the images. For a complete list of supported languages and their codes, you can consult the official Tesseract documentation. (default value: fra)
input_path: Path to the folder containing the files to be processed.
output_path: Path to the folder where the results will be saved.
cache_folder_path: Path to the folder containing the JSON cache files that will be created for each subfolder. This directory will store the cache files for processed documents, significantly reducing processing time when the same documents are processed multiple times in future runs. If this parameter is not provided or if the path is invalid, the function will not save any cache, and the processing time will be longer.

Outputs
The find_keyword_xtvu function will generate the following three Excel workbooks (.xlsx):

A file containing the results of the keywords found in the documents, with a name that can be defined by the result_keyword_table_name argument in the find_keyword_xtvu function.
A file containing the contingency tables of keyword frequency in the documents, with a name that can be defined by the freque_document_keyword_table_name argument in the find_keyword_xtvu function. Each contingency table shows how many times each keyword was found in each document within a specific folder.
A file listing problematic files, named heavy_or_slow_df.xlsx.

Contribution
As the author of this library, I would like to thank Madame Sylvie HUET, researcher at LISC, INRAE, Centre Clermont-Auvergne-RhĂŽne-Alpes, France, for her valuable contributions.
Contributions are welcome! If you would like to improve this project or if you have any questions, feel free to contact me at vuxuantung09134@gmail.com (in French, English, or Vietnamese).
License
This project is licensed under the MIT License. See the LICENSE file for details.
Version Française
Le package Python find_keyword_xtvu facilite la recherche de mots-clĂ©s dans les fichiers PDF, DOCX, ODT et RTF, permettant d'extraire les phrases contenant ces mots-clĂ©s. Il offre Ă©galement un support pour plusieurs langues et peut s'exĂ©cuter sur des CPU multicƓurs.
Installation
Vous pouvez installer ce package via pip :
pip install find-keyword-xtvu==<derniĂšre_version_sur_PyPi>

Structure du RĂ©pertoire
L'organisation du dossier contenant le code .py et les documents peut ĂȘtre structurĂ©e comme suit :
/Dossier parent
│
├── script_principal.py # Le script Python principal
│
├── fichiers_entre # Dossier contenant les sous-dossiers de fichiers PDF
│ ├── files1 # Sous-dossier contenant les fichiers .pdf, .docx, .otd et .rtf d'entrĂ©e
│ ├── files2
│ ├── files3
│ ...
└── resultats # Dossier contenant les rĂ©sultats

Utilisation


Placez les fichiers dans le répertoire d'entrée :

Mettez les fichiers PDF, DOCX, ODT, ou RTF que vous souhaitez analyser dans les sous-dossiers du dossier fichiers_entree. Par défaut, vous pouvez les organiser dans un seul sous-dossier (par exemple, files1) ou dans plusieurs sous-dossiers (files2, files3, etc.), selon vos besoins.



Définissez les mots-clés :

Ouvrez le script script_principal.py et modifiez la liste KEYWORDS pour inclure les mots-clés que vous souhaitez rechercher dans les fichiers.



Exécutez le script :

Exécutez le script script_principal.pydans un IDE comme Visual Studio Code.



Le fichier script_principal.py utilise le package find_keyword_xtvu et peut ĂȘtre organisĂ© comme suit :
from find_keyword_xtvu import find_keyword_xtvu
if __name__ == "__main__":
find_keyword_xtvu(
prefixe_langue = 'fr',
threads_rest = None,
nb_phrases_avant = 10,
nb_phrases_apres = 10,
keywords = [["",""],""],
exact_match = True,
taille = 20,
timeout = 200,
result_keyword_table_name = "",
freque_document_keyword_table_name = "",
fusion_keyword_before_after = False,
tesseract_cmd = "/usr/local/bin/tesseract",
use_tesseract = False,
use_full_tesseract = False,
lang_OCR_tesseract = 'fra',
input_path = "/path/to/fichiers_entre",
output_path = "/path/to/resultats",
cache_folder_path = "/path/to/cache_folder"
)

Arguments

prefixe_langue : Préfixe de langue pour spécifier le modÚle linguistique à utiliser (valeur par défaut : 'fr'). Pour connaßtre les langues supportées et leurs préfixes, consultez la documentation SpaCy. Si vous fournissez un préfixe non supporté, ou si vous souhaitez utiliser le modÚle multilingue, spécifiez l'argument multi. Dans les deux cas, le modÚle multilingue xx_ent_wiki_sm sera utilisé. En savoir plus sur ce modÚle ici.
threads_rest : Nombre de threads rĂ©servĂ©s pour d'autres tĂąches. Si non spĂ©cifiĂ©, la bibliothĂšque utilisera par dĂ©faut la moitiĂ© des cƓurs disponibles.
nb_phrases_avant : Nombre de phrases à inclure avant le mot-clé (valeur par défaut : 10).
nb_phrases_apres : Nombre de phrases à inclure aprÚs le mot-clé (valeur par défaut : 10).
keywords : Liste de mots-clĂ©s Ă  rechercher. Pour regrouper plusieurs mots-clĂ©s qui doivent ĂȘtre traitĂ©s de la mĂȘme maniĂšre, utilisez un format de liste comme ["mot1", "mot2"] (par exemple, ["local", "proche"] pour les traiter comme des synonymes). Si vous souhaitez traiter les mots-clĂ©s sĂ©parĂ©ment, placez chaque mot-clĂ© sous forme de chaĂźne de caractĂšres individuelle, comme "mot". Par exemple, si nous structurons la liste ainsi [["local", "proche"], "Ă©cole", "bibliothĂšque", "parc"], cela signifie que "local" et "proche" seront traitĂ©s comme des synonymes, tandis que "Ă©cole", "bibliothĂšque" et "parc" seront chacun traitĂ©s comme des mots-clĂ©s distincts.
exact_match : Ce paramÚtre booléen détermine si la recherche du mot-clé doit correspondre exactement au mot fourni. S'il est réglé sur True, seules les correspondances exactes du mot-clé seront prises en compte lors de l'extraction du texte. S'il est réglé sur False, la recherche sera basée sur le lemme du mot-clé, ce qui permet une correspondance plus flexible en capturant différentes variations du mot (par exemple, "courir", "courant", "couru"). Pour en savoir plus sur les formes de lemmes, consultez cette page.
taille : Taille maximale des fichiers à traiter en mégaoctets (valeur par défaut : 20 MB).
timeout : Durée maximale pour le traitement d'une page en secondes (valeur par défaut : 200).
result_keyword_table_name : Nom de la table pour les résultats des mots-clés. Si ce champ est vide, un nom par défaut pour cette table sera res.
freque_document_keyword_table_name : Nom de la table pour les résultats des tables de contingence de la fréquence des mots-clés dans chaque dossier de fichiers. Si ce champ est vide, le nom par défaut pour cette table sera freque_document_keyword.
fusion_keyword_before_after : Ce paramĂštre boolĂ©en contrĂŽle si la fonction doit Ă©viter d'inclure des phrases redondantes lorsque un mot-clĂ© apparaĂźt plusieurs fois Ă  proximitĂ© dans le texte. Lorsqu'il est dĂ©fini sur True, la fonction garantira que les phrases entourant un mot-clĂ© sont extraites une seule fois, mĂȘme si elles chevauchent les phrases entourant une autre occurrence du mĂȘme mot-clĂ©. Cela empĂȘche la rĂ©pĂ©tition de phrases dans le rĂ©sultat final, conduisant Ă  un rĂ©sultat plus concis. Si dĂ©fini sur False, la fonction extraira toutes les phrases entourant chaque occurrence du mot-clĂ©, ce qui peut conduire Ă  une redondance si le mot-clĂ© apparaĂźt frĂ©quemment dans le texte. (valeur par dĂ©faut : False)
tesseract_cmd : Chemin vers l'exécutable Tesseract (valeur par défaut : "/usr/local/bin/tesseract").
use_tesseract : Ce paramĂštre boolĂ©en dĂ©termine si l'on doit utiliser Tesseract OCR pour traiter les images dans les documents. Lorsqu'il est dĂ©fini sur True, la fonction extraira le texte des images en utilisant Tesseract OCR, ce qui est utile si les documents contiennent des images scannĂ©es ou des images intĂ©grĂ©es avec du texte. Assurez-vous que tesseract_cmd est correctement configurĂ© pour pointer vers le chemin de l'exĂ©cutable Tesseract. Si le paramĂštre est dĂ©fini sur False, la fonction ignorera les images dans les documents et traitera uniquement le texte directement extractible sans OCR. Cela peut ĂȘtre plus rapide et Ă©vite la nĂ©cessitĂ© d'installer Tesseract. (valeur par dĂ©faut : False)
use_full_tesseract : Ce paramĂštre boolĂ©en contrĂŽle si Tesseract OCR doit ĂȘtre appliquĂ© Ă  l'ensemble de la page du document. Lorsqu'il est activĂ©, la page entiĂšre est convertie en image, et Tesseract est utilisĂ© pour extraire le texte de l'image complĂšte. Cela permet une extraction de texte plus prĂ©cise et prĂ©serve la structure du document, mais cela est plus intensif en termes de calcul. Si seul use_tesseract est activĂ© sans use_full_tesseract, Tesseract n'extraira le texte que des images spĂ©cifiques sur la page, plutĂŽt que de la page entiĂšre. (valeur par dĂ©faut : False)
lang_OCR_tesseract: Code de langue utilisé par Tesseract OCR pour identifier la langue du texte à extraire des images. Par défaut, ce paramÚtre est réglé sur 'fra' pour le français. Vous pouvez spécifier d'autres codes de langue pris en charge par Tesseract selon la langue du texte dans les images. Pour une liste complÚte des langues et de leurs codes supportés par Tesseract, vous pouvez consulter la documentation officielle de Tesseract.
input_path : Chemin vers le dossier contenant les fichiers Ă  traiter.
output_path : Chemin vers le dossier oĂč les rĂ©sultats seront enregistrĂ©s.
cache_folder_path : Chemin vers le dossier contenant les fichiers cache JSON, crĂ©Ă©s pour chaque sous-dossier. Ce rĂ©pertoire stockera les fichiers cache pour les documents traitĂ©s, rĂ©duisant ainsi considĂ©rablement le temps de traitement lorsque les mĂȘmes documents sont traitĂ©s plusieurs fois lors des exĂ©cutions futures. Si ce paramĂštre n'est pas fourni ou si le chemin est invalide, la fonction ne sauvegardera aucun cache, et le temps de traitement sera plus long.

Sorties
La fonction find_keyword_xtvu va générer trois classeurs Excel (.xlsx) suivants :

Un fichier contenant les rĂ©sultats des mots-clĂ©s trouvĂ©s dans les documents avec un nom pouvant ĂȘtre dĂ©fini par l'argument result_keyword_table_name dans la fonction find_keyword_xtvu.
Un fichier contenant les tables de contingence de la frĂ©quence des mots-clĂ©s dans les documents avec un nom pouvant ĂȘtre dĂ©fini par l'argument freque_document_keyword_table_name dans la fonction find_keyword_xtvu. Chaque table de contingence montre combien de fois chaque mot-clĂ© a Ă©tĂ© trouvĂ© dans chaque document au sein d'un dossier spĂ©cifique.
Un fichier répertoriant les fichiers problématiques, nommé heavy_or_slow_df.xlsx.

Contribution
En tant qu'auteur de cette bibliothÚque, je tiens à remercier Madame Sylvie HUET, chercheuse au LISC, INRAE, Centre Clermont-Auvergne-RhÎne-Alpes, France, pour ses précieuses contributions.
Les contributions sont les bienvenues ! Si vous souhaitez améliorer ce projet ou si vous avez des questions, n'hésitez pas à me contacter à l'adresse vuxuantung09134@gmail.com (en français, anglais ou vietnamien).
Licence
Ce projet est sous licence MIT. Voir le fichier LICENSE pour plus de détails.
📜 Older Updates
✹ What's New in Version 5.6.9

🆕 Enhanced Keyword Frequency Tracking: In this update, I have introduced additional columns to the results DataFrame when the fusion_keyword_before_after argument is set to True. These columns represent the frequency of each keyword found in the analyzed phrases, offering more detailed insights into keyword occurrences. These new frequency columns are automatically appended after the Info column.

✹ What's New in Version 5.6.8

❗Important Change to Argument: To simplify the requirements of this library, I have decided to remove the dependency on Poppler. Now, you don’t need to download Poppler to use this library. This change simplifies the process for the average user.
🆕 New Argument use_full_tesseract: This new argument allows you to decide whether to apply Tesseract to the entire document. This option enables us to extract text while maintaining the structure of the text, which is beneficial for users with high-performance computers.

✹ What's New in Version 5.6.7

🔧 Bug Fix: Fixed the error in generating contingency tables and calculating occurrences of keywords in a sentence.

✹ What's New in Version 5.6.6

🚀 Enhanced Keyword Processing: The library now supports the identification and handling of synonymous keywords. You can search for individual keywords or groups of synonymous keywords, and they will all be treated equivalently, ensuring a more flexible and accurate search process.

✹ What's New in Version 5.6.4

🚀 Improvement in the way documents are read: Enhanced the document reading methods to produce more accurate results.

✹ What's New in Version 5.6.2

🆕 New argument exact_match: Enables precise matching of the keyword during text extraction. If set to False, the matching will be based on the lemma form, allowing for more flexible searches and capturing different forms of the word.
🆕 New modification to threads_rest: To prevent potential blocking on certain computers, the default number of cores used by this code is now set to half of the available cores, ensuring smoother operation without overloading the system. If your computer is lagging significantly, you may want to increase this number to help resolve the issue.

đŸ› ïž What's New in Version 5.6.1

🔧 Bug Fix: Minor bug fixes to enhance stability.

✹ What's New in Version 5.6

🆕 New argument lang_OCR_tesseract: Add the ability to specify the language of the Tesseract OCR model for extracting text from images.

đŸ› ïž What's New in Version 5.5.9

🔧 Bug Fix with poppler_path: Solves the issue with "Unable to get page count. Is poppler installed and in PATH?" by allowing you to specify the Poppler installation path.

✹ What's New in Version 5.5.8

🆕 New argument use_tesseract: Adds an option to use Tesseract OCR for extracting text from images within documents. When set to False, only text is processed without OCR.

đŸ› ïž What's New in Version 5.5.7

🔧 Bug Fix: Minor bug fixes to enhance stability.

đŸ› ïž What's New in Version 5.5.6

🔧 Bug Fix: Resolved the tesseract not found issue.
🔄 Update: All log messages are now standardized in English.

đŸ› ïž What's New in Version 5.5.5

🔧 Bug Fix: Corrected an issue with calculating contingency tables of keyword frequency when fusion_keyword_before_after = True.

đŸ› ïž What's New in Version 5.5.4

🔧 Bug fix: Fixed an issue where some document names couldn't be read correctly.
🆕 New argument fusion_keyword_before_after: Introduces the ability to merge phrases to avoid redundancy in the results.

🌍 What's New in Version 5.5.2

🌐 Multilingual Support: This version now includes support for multiple languages by integrating SpaCy's NLP models. You can now search for keywords and extract sentences in languages such as English, French, German, Spanish, and more. The supported models are listed in the SpaCy documentation.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.