### Install PassivePy and Dependencies Source: https://context7.com/mitramir55/passivepy/llms.txt Commands to install the PassivePy library and the required spaCy language models for NLP processing. ```bash pip install -r https://raw.githubusercontent.com/mitramir55/PassivePy/main/PassivePyCode/PassivePySrc/requirements_lg.txt pip install PassivePy==0.2.22 pip install -r https://raw.githubusercontent.com/mitramir55/PassivePy/main/PassivePyCode/PassivePySrc/requirements_sm.txt ``` -------------------------------- ### Install PassivePy Requirements Source: https://github.com/mitramir55/passivepy/blob/main/README.md Installs the necessary requirements for PassivePy and its dependencies, such as spaCy models. This step is crucial before using the library. ```bash !pip install -r https://raw.githubusercontent.com/mitramir55/PassivePy/main/PassivePyCode/PassivePySrc/requirements_lg.txt !pip install PassivePy==0.2.21 ``` -------------------------------- ### Install PassivePy and Dependencies Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Installs the PassivePy package and its required dependencies from a remote requirements file. This is typically run in a Jupyter notebook or shell environment. ```bash !pip install -r https://raw.githubusercontent.com/mitramir55/PassivePy/main/PassivePyCode/PassivePySrc/requirements_lg.txt !pip install PassivePy ``` -------------------------------- ### Manage and Analyze Datasets Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Demonstrates how to load datasets using pandas, export analysis results to CSV, and clone the repository for sample data access. ```python import pandas as pd import os # Exporting data table_2.to_csv('table_2.csv', index=True) # Loading datasets df = pd.read_csv('PassivePy\\Data\\crowd_source_dataset.csv') df_without = pd.read_csv(r'D:\\Papers\\Paper 3 - Recommender Systems\\additional on passivepy\\cola_analyzed_without.csv') # Data manipulation df_with = df_without[['document', 'uid']] ``` -------------------------------- ### Initialize PassivePyAnalyzer Source: https://context7.com/mitramir55/passivepy/llms.txt Demonstrates how to instantiate the PassivePyAnalyzer using different spaCy model configurations, including pre-loaded models. ```python from PassivePySrc import PassivePy import spacy # Initialize with the large English model passivepy = PassivePy.PassivePyAnalyzer(spacy_model="en_core_web_lg") # Initialize with a custom pre-loaded spaCy model nlp = spacy.load("en_core_web_lg", disable=["ner"]) passivepy_custom = PassivePy.PassivePyAnalyzer(nlp=nlp) ``` -------------------------------- ### Initialize PassivePy Analyzer Source: https://github.com/mitramir55/passivepy/blob/main/README.md Imports the PassivePy library and initializes the PassivePyAnalyzer. This sets up the object for performing passive voice detection using a specified spaCy model. ```python from PassivePySrc import PassivePy passivepy = PassivePy.PassivePyAnalyzer(spacy_model = "en_core_web_lg") ``` -------------------------------- ### Load and Inspect CSV Data Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Demonstrates loading a processed dataset from a CSV file using pandas and displaying the first few rows for inspection. ```python df_without = pd.read_csv(r"D:\Papers\Paper 3 - Recommender Systems\additional on passivepy\re_analysis_crowdsource.csv") df_without.head() ``` -------------------------------- ### Initialize spaCy NLP Model Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Loads a pre-trained English language model using spaCy. This is a prerequisite for performing NLP tasks like tokenization, POS tagging, and dependency parsing. ```python import spacy from spacy import displacy spacy_model = "en_core_web_lg" nlp = spacy.load(spacy_model) ``` -------------------------------- ### Visualize Dependency Parsing Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Processes text through the spaCy pipeline and serves a dependency visualization using displaCy. Note that displacy.render is preferred for Jupyter environments. ```python text = 'beautiful day' doc = nlp(text) displacy.serve(doc, style = "dep", options={"compact":False}) ``` -------------------------------- ### Process Large Datasets with Batching and Multiprocessing Source: https://context7.com/mitramir55/passivepy/llms.txt Shows how to process large CSV or Excel files using optimized batch sizes and parallel processing to improve performance. ```python from PassivePySrc import PassivePy import pandas as pd passivepy = PassivePy.PassivePyAnalyzer(spacy_model="en_core_web_lg") # Load and process dataset df = pd.read_csv('research_abstracts.csv') df_results = passivepy.match_corpus_level( df, column_name='abstract_text', n_process=-1, batch_size=500, add_other_columns=True ) # Save results df_results.to_csv('passive_analysis_results.csv', index=False) ``` -------------------------------- ### Analyze Passive Voice in Sentences Source: https://context7.com/mitramir55/passivepy/llms.txt Demonstrates how to use PassivePy to parse individual sentences and inspect dependency structures for passive voice detection. ```python import passivepy # Analyze an active sentence active_sentence = "The committee reviewed the report." active_df = passivepy.parse_sentence(active_sentence) print(active_df) # Analyze a passive sentence for debugging test_sentence = "She has been informed about the changes." test_df = passivepy.parse_sentence(test_sentence) print(test_df.loc['dependency']) ``` -------------------------------- ### POST /match_text Source: https://context7.com/mitramir55/passivepy/llms.txt Analyzes a single sentence or short text for passive voice constructions, returning a DataFrame with detection metrics. ```APIDOC ## POST /match_text ### Description Analyzes a single string of text to identify passive voice constructions. Supports filtering by full passive (with agent) or truncated passive (without agent). ### Method POST ### Endpoint /match_text ### Parameters #### Request Body - **text** (string) - Required - The sentence or short text to analyze. - **full_passive** (boolean) - Optional - Whether to detect passive constructions with an agent (default: True). - **truncated_passive** (boolean) - Optional - Whether to detect passive constructions without an agent (default: True). ### Request Example { "text": "The book was read by him.", "full_passive": true, "truncated_passive": false } ### Response #### Success Response (200) - **all_passives** (list) - List of matched passive spans. - **passive_count** (integer) - Total count of passive constructions found. - **binary** (integer) - 1 if passive voice is detected, 0 otherwise. #### Response Example { "all_passives": ["was read by"], "passive_count": 1, "binary": 1 } ``` -------------------------------- ### Perform Sentence-Level Dataset Analysis Source: https://context7.com/mitramir55/passivepy/llms.txt Demonstrates how to process a pandas DataFrame to detect passive voice at the sentence level, preserving document metadata. ```python from PassivePySrc import PassivePy import pandas as pd passivepy = PassivePy.PassivePyAnalyzer(spacy_model="en_core_web_lg") # Process a DataFrame column for sentence-level passive detection df_sentence = passivepy.match_sentence_level( df, column_name='documents', n_process=1, batch_size=1000, add_other_columns=True ) ``` -------------------------------- ### Debug Pattern Matching with print_matches Source: https://context7.com/mitramir55/passivepy/llms.txt Uses the print_matches method to visualize which passive rules were triggered by specific input strings. This is useful for validating pattern detection logic. ```python from PassivePySrc import PassivePy passivepy = PassivePy.PassivePyAnalyzer(spacy_model="en_core_web_lg") # Debug all passive matches passivepy.print_matches("The book was read by him.") # Debug truncated passive matches only passivepy.print_matches("The window was broken.", truncated_passive=True) # Test complex sentence with multiple passives passivepy.print_matches( "The data was collected and analyzed by the research team.", truncated_passive=False, full_passive=False ) ``` -------------------------------- ### Analyze Single Text for Passive Voice Source: https://context7.com/mitramir55/passivepy/llms.txt Shows how to analyze a single string for passive voice, including options to filter for full or truncated passive constructions. ```python from PassivePySrc import PassivePy passivepy = PassivePy.PassivePyAnalyzer(spacy_model="en_core_web_lg") # Analyze for all passive types result = passivepy.match_text("The painting has been drawn by the artist.") # Analyze specifically for full passives result_full = passivepy.match_text("The book was written by Shakespeare.", full_passive=True, truncated_passive=False) # Analyze specifically for truncated passives result_truncated = passivepy.match_text("The window was broken.", truncated_passive=True, full_passive=False) ``` -------------------------------- ### POST /match_sentence_level Source: https://context7.com/mitramir55/passivepy/llms.txt Processes a dataset (DataFrame) to perform sentence-level passive voice detection, tracking document and sentence IDs. ```APIDOC ## POST /match_sentence_level ### Description Analyzes a collection of documents at the sentence level. Each sentence is treated as an individual record, allowing for granular analysis of passive voice usage across large datasets. ### Method POST ### Endpoint /match_sentence_level ### Parameters #### Request Body - **df** (DataFrame) - Required - The input dataset containing text documents. - **column_name** (string) - Required - The column containing the text to analyze. - **n_process** (integer) - Optional - Number of processes for parallel execution (default: 1). - **batch_size** (integer) - Optional - Batch size for processing (default: 1000). ### Request Example { "column_name": "documents", "n_process": 4, "batch_size": 500 } ### Response #### Success Response (200) - **df_sentence** (DataFrame) - A DataFrame where each row represents a sentence, including passive detection results and original metadata. #### Response Example { "status": "success", "rows_processed": 150 } ``` -------------------------------- ### Analyze passive voice at the corpus level Source: https://context7.com/mitramir55/passivepy/llms.txt Uses the match_corpus_level method to aggregate passive voice statistics across entire documents. It returns metrics such as passive counts, sentence counts, and percentages per document. ```python df_corpus = passivepy.match_corpus_level( df, column_name='text', n_process=-1, batch_size=1000, add_other_columns=True, truncated_passive=True, full_passive=True ) high_passive = df_corpus[df_corpus['passive_percentages'] > 0.5] ``` -------------------------------- ### match_corpus_level - Corpus-Level Dataset Analysis Source: https://context7.com/mitramir55/passivepy/llms.txt Processes a DataFrame and aggregates passive voice statistics at the document/corpus level. It returns one row per document with counts, percentages, and all passive matches aggregated. ```APIDOC ## POST /match_corpus_level ### Description Processes a DataFrame and aggregates passive voice statistics at the document/corpus level. Returns one row per document with counts, percentages, and all passive matches aggregated. ### Method POST ### Endpoint /match_corpus_level ### Parameters #### Request Body - **df** (DataFrame) - Required - DataFrame containing the text to analyze. - **column_name** (string) - Required - The name of the column containing the text. - **n_process** (integer) - Optional - Number of CPU cores to use for multiprocessing. -1 uses all available cores. - **batch_size** (integer) - Optional - Number of records to process per batch. - **add_other_columns** (boolean) - Optional - Whether to include other columns from the input DataFrame in the output. - **truncated_passive** (boolean) - Optional - Whether to detect truncated passive constructions. - **full_passive** (boolean) - Optional - Whether to detect full passive constructions. ### Request Example ```json { "df": "[DataFrame object]", "column_name": "text", "n_process": 1, "batch_size": 1000, "add_other_columns": true, "truncated_passive": true, "full_passive": true } ``` ### Response #### Success Response (200) - **document** (string) - Identifier for the document. - **count_sents** (integer) - Total number of sentences in the document. - **all_passives** (list) - A list of all detected passive voice phrases in the document. - **passive_count** (integer) - The total count of passive voice instances in the document. - **passive_sents_count** (integer) - The count of sentences containing passive voice. - **passive_percentages** (float) - The percentage of sentences containing passive voice. - **binary** (integer) - Binary indicator (1 if passive voice is detected in any sentence, 0 otherwise). - **paper_id** (string) - Paper ID if available. - **journal** (string) - Journal name if available. #### Response Example ```json { "document": "doc1", "count_sents": 4, "all_passives": ["was designed", "were collected", "was performed", "were published"], "passive_count": 4, "passive_sents_count": 4, "passive_percentages": 1.00, "binary": 1, "paper_id": "A001", "journal": "Nature" } ``` ``` -------------------------------- ### match_sentence_level - Sentence-Level Passive Detection Source: https://context7.com/mitramir55/passivepy/llms.txt Analyzes text at the sentence level to detect passive voice. It can return various details including sentence IDs, passive voice presence (binary), and lists of all detected passive constructions. ```APIDOC ## POST /match_sentence_level ### Description Analyzes text at the sentence level to detect passive voice. It can return various details including sentence IDs, passive voice presence (binary), and lists of all detected passive constructions. ### Method POST ### Endpoint /match_sentence_level ### Parameters #### Request Body - **df** (DataFrame) - Required - DataFrame containing the text to analyze. - **column_name** (string) - Required - The name of the column containing the text. - **n_process** (integer) - Optional - Number of CPU cores to use for multiprocessing. -1 uses all available cores. - **batch_size** (integer) - Optional - Number of records to process per batch. - **add_other_columns** (boolean) - Optional - Whether to include other columns from the input DataFrame in the output. - **truncated_passive** (boolean) - Optional - Whether to detect truncated passive constructions. - **full_passive** (boolean) - Optional - Whether to detect full passive constructions. ### Request Example ```json { "df": "[DataFrame object]", "column_name": "documents", "n_process": 4, "batch_size": 500, "add_other_columns": true, "truncated_passive": true, "full_passive": true } ``` ### Response #### Success Response (200) - **docId** (integer) - The ID of the document. - **sentenceId** (integer) - The ID of the sentence. - **sentences** (string) - The text of the sentence. - **all_passives** (list) - A list of all detected passive voice phrases in the sentence. - **all_passives_count** (integer) - The count of all detected passive voice phrases. - **binary** (integer) - Binary indicator (1 if passive voice is detected, 0 otherwise). - **category** (string) - Category of the passive voice detected. - **author** (string) - Author information if available. #### Response Example ```json { "docId": 1, "sentenceId": 1, "sentences": "The experiment was conducted carefully.", "all_passives": ["was conducted"], "all_passives_count": 1, "binary": 1, "category": "passive", "author": "Unknown" } ``` ``` -------------------------------- ### Analyze passive voice at the sentence level Source: https://context7.com/mitramir55/passivepy/llms.txt Uses the match_sentence_level method to identify passive voice constructions within a DataFrame of sentences. It supports multiprocessing for performance and allows toggling between truncated and full passive detection. ```python df_detailed = passivepy.match_sentence_level( df, column_name='documents', n_process=4, batch_size=500, add_other_columns=True, truncated_passive=True, full_passive=True ) passive_sentences = df_detailed[df_detailed['binary'] == 1] ``` -------------------------------- ### Detect Passive Voice in Text Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Uses passivepy.match_text to identify passive voice constructions in a given string. It supports full and truncated passive detection and returns a detailed analysis table. ```python import passivepy sample_text = "Bears are dreamt of in your fantasies!" resutl_1 = passivepy.match_text(sample_text, full_passive=True, truncated_passive=True) print(resutl_1) ``` -------------------------------- ### parse_sentence - Token Analysis Source: https://context7.com/mitramir55/passivepy/llms.txt Analyzes the linguistic components of a sentence, returning part-of-speech tags, dependencies, and lemmas for each token. This is useful for understanding why passive voice was detected. ```APIDOC ## POST /parse_sentence ### Description Analyzes the linguistic components of a sentence, returning part-of-speech tags, dependencies, and lemmas for each token. Useful for understanding why passive voice was detected. ### Method POST ### Endpoint /parse_sentence ### Parameters #### Request Body - **sentence** (string) - Required - The sentence to analyze. - **spacy_model** (string) - Optional - The spaCy model to use for analysis (e.g., "en_core_web_lg"). ### Request Example ```json { "sentence": "The report was carefully reviewed by the committee.", "spacy_model": "en_core_web_lg" } ``` ### Response #### Success Response (200) - **DataFrame** - A pandas DataFrame where columns represent tokens and rows represent linguistic features (POS, dependency, tag, lemma). #### Response Example ```json { "DataFrame": { "The": {"POS": "DET", "dependency": "det", "tag": "DT", "lemma": "the"}, "report": {"POS": "NOUN", "dependency": "nsubjpass", "tag": "NN", "lemma": "report"}, "was": {"POS": "AUX", "dependency": "auxpass", "tag": "VBD", "lemma": "be"}, "carefully": {"POS": "ADV", "dependency": "advmod", "tag": "RB", "lemma": "carefully"}, "reviewed": {"POS": "VERB", "dependency": "ROOT", "tag": "VBN", "lemma": "review"}, "by": {"POS": "ADP", "dependency": "agent", "tag": "IN", "lemma": "by"}, "the": {"POS": "DET", "dependency": "det", "tag": "DT", "lemma": "the"}, "committee": {"POS": "NOUN", "dependency": "pobj", "tag": "NN", "lemma": "committee"}, ".": {"POS": "PUNCT", "dependency": "punct", "tag": ".", "lemma": "."} } } ``` ``` -------------------------------- ### Detect Passive Voice at Corpus Level Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Uses the match_corpus_level function to aggregate passive voice statistics across a document corpus. This is useful for analyzing passive voice frequency at the document level. ```python df_detected_c = passivepy.match_corpus_level(df, column_name='Sentence', n_process = 1, batch_size = 1000, add_other_columns=True, truncated_passive=False, full_passive=False) df_detected_c ``` -------------------------------- ### Detect Passive Voice at Sentence Level Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Uses the match_sentence_level function to identify passive voice constructions within a dataframe at the sentence granularity. It returns a dataframe with detected passive voice information for each sentence. ```python df_detected_s = passivepy.match_sentence_level(df, column_name='Sentence', n_process = 1, batch_size = 1000, add_other_columns=True, truncated_passive=False, full_passive=False) df_detected_s ``` -------------------------------- ### Merge DataFrames by UID in Python Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb This snippet demonstrates how to merge two DataFrames, df_without and df_detected_c, using the 'uid' column as the join key. It applies specific suffixes to distinguish between columns originating from the two source DataFrames. ```python import pandas as pd df_merged = pd.merge(df_without, df_detected_c, on='uid', suffixes=('_without', '_with')) ``` -------------------------------- ### Analyze Single Sentence with PassivePy Source: https://github.com/mitramir55/passivepy/blob/main/README.md Analyzes a single text string to detect passive voice. It can identify both full passive and truncated passive forms based on the provided boolean flags. ```python # Try changing the sentence below: sample_text = "The painting has been drawn." passivepy.match_text(sample_text, full_passive=True, truncated_passive=True) ``` -------------------------------- ### Parse linguistic components of a sentence Source: https://context7.com/mitramir55/passivepy/llms.txt Uses the parse_sentence method to return a DataFrame containing part-of-speech tags, dependency relations, and lemmas for each token in a sentence. ```python sentence = "The report was carefully reviewed by the committee." token_df = passivepy.parse_sentence(sentence) print(token_df) ``` -------------------------------- ### Process Dataset at Corpus Level Source: https://github.com/mitramir55/passivepy/blob/main/README.md Analyzes a dataset at the corpus level to detect passive voice. This function processes entire documents in a specified column of a DataFrame and returns a DataFrame with aggregated results. ```python # corpus level df_detected_c = passivepy.match_corpus_level(df, column_name='sentences', n_process = 1, batch_size = 1000, add_other_columns=True, truncated_passive=False, full_passive=False) ``` -------------------------------- ### Process Dataset at Sentence Level Source: https://github.com/mitramir55/passivepy/blob/main/README.md Analyzes a dataset at the sentence level to detect passive voice. This function processes each sentence in a specified column of a DataFrame and returns a DataFrame with detection results. ```python # sentence level: df_detected_s = passivepy.match_sentence_level(df, column_name='documents', n_process = 1, batch_size = 1000, add_other_columns=True, truncated_passive=False, full_passive=False) ``` -------------------------------- ### Calculate Accuracy Metric Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Computes the accuracy of a binary classification model by comparing human-coded labels against predicted binary values. It returns the ratio of correct predictions to total samples. ```python len(df_detected_c[df_detected_c['human_coding']==df_detected_c['binary']])/len(df_detected_c) ``` -------------------------------- ### Parse Sentences for Linguistic Features Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Uses passivepy.parse_sentence to extract POS tags, dependency relations, and lemmas from input sentences. This provides a granular view of the grammatical structure. ```python import passivepy table_1 = passivepy.parse_sentence("Bears are dreamt of in your fantasies!") table_2 = passivepy.parse_sentence("Book was read by him.") print(table_1) print(table_2) ``` -------------------------------- ### Parse Sentences with PassivePy Source: https://github.com/mitramir55/passivepy/blob/main/README.md The parse_sentence method analyzes a given string to extract linguistic features such as dependency relations, part-of-speech tags, and lemmas for each token. This function is useful for granular linguistic inspection of sentences. ```python import passivepy sample_sentence = "She has been killed" passivepy.parse_sentence(sample_sentence) ``` -------------------------------- ### Filter Dataframe for Discrepancies Source: https://github.com/mitramir55/passivepy/blob/main/PassivePy notebook.ipynb Filters a pandas DataFrame to identify rows where passive counts differ between two conditions. This is useful for validating data consistency across merged datasets. ```python df_merged[df_merged['passive_count_without'] != df_merged['passive_count_with']] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.