Core Module
The core module provides the main functionality for extracting woseco concept associations from text.
WosecoExtractor Class
Usage Example
from wosecopy import WosecoExtractor
import pandas as pd
# Initialize extractor
extractor = WosecoExtractor(language='en', model_size='lg')
# Process a DataFrame
df = pd.DataFrame({'Story': ['Once upon a time...']})
concepts = extractor.get_woseco(df)
# Process a CSV file
result_df = extractor.process_csv(
'input.csv',
text_column='Story',
output_path='output.csv'
)
Key Methods
get_concept_matches
Match concepts between consecutive sentences using semantic similarity.
Algorithm:
Compare all noun pairs between consecutive sentences
Calculate similarity using spaCy word embeddings
Select pair with maximum similarity
Build chain of linked concepts
Example:
concept_list = [
['belief', 'village'],
['faith', 'people'],
['church', 'community']
]
chain = extractor.get_concept_matches(concept_list)
# Returns: ['belief', 'faith', 'church', 'community']
get_woseco
Main function to extract woseco concepts from a DataFrame.
Process:
Split each story into sentences (by periods)
Extract nouns from each sentence
Match concepts between consecutive sentences
Return list of concept chains
Example:
df = pd.DataFrame({
'Story': [
'There was belief. Faith followed.',
'Music played. Songs filled the air.'
]
})
concepts = extractor.get_woseco(df)
# Returns: [['belief', 'faith'], ['music', 'song', 'air']]
extract_nouns
Extract and lemmatize nouns from text.
Example:
text = "The dogs are running in the parks."
nouns = extractor.extract_nouns(text)
# Returns: ['dog', 'park']
process_csv
End-to-end processing of a CSV file.
Example:
df = extractor.process_csv(
'stories.csv',
text_column='Story',
output_path='results.csv',
similarity_threshold=0.5
)