compass.extraction.wind.plugin.COMPASSWindExtractor#
- class COMPASSWindExtractor(jurisdiction, model_configs, usage_tracker=None)[source]#
Bases:
OrdinanceExtractionPluginCOMPASS wind extraction plugin
- Parameters:
jurisdiction (
Jurisdiction) – Jurisdiction for which extraction is being performed.model_configs (
dict) – Dictionary where keys areLLMTasksand values areLLMConfiginstances to be used for those tasks.usage_tracker (
UsageTracker, optional) – Usage tracker instance that can be used to record the LLM call cost. By default,None.
Methods
extract_ordinances_from_text(doc, ...)Extract structured data from input text
extract_relevant_text(doc, extractor_class, ...)Condense text for extraction task
filter_docs(extraction_context[, ...])Filter down candidate documents before parsing
Get a BaseHeuristic instance with a check() method
Get a list of search engine query templates for extraction
get_structured_data_row_count(data_df)Get the number of data rows extracted from a document
Get a dict of website search keyword scores
Parse documents to extract structured data/information
parse_for_structured_data(source)Extract all possible structured data from a document
Parse all documents to extract structured data/information
Parse documents one at a time to extract structured data
post_filter_docs_hook(extraction_context)Post-process documents after running them through the filter
pre_filter_docs_hook(extraction_context)Pre-process documents before running them through the filter
Persist usage tracking data when a tracker is available
save_structured_data(doc_infos, out_dir)Write extracted water rights data to disk
Attributes
Whether to allow extraction over multiple documents
Identifier for extraction task
Path to jurisdiction CSV
Class for parsing structured ordinance data from text
List of search engine query templates for extraction
Classes for collecting wind ordinance text chunks from docs
Class for extracting cleaned ord text from collected text
List of keywords
Pairs of (consumer, producer) for IN/OUT validation
All classes that produce attributes on the doc
- QUERY_TEMPLATES = ['filetype:pdf {jurisdiction} wind energy conversion system ordinances', 'wind energy conversion system ordinances {jurisdiction}', '{jurisdiction} wind WECS ordinance', 'Where can I find the legal text for commercial wind energy conversion system zoning ordinances in {jurisdiction}?', 'What is the specific legal information regarding zoning ordinances for commercial wind energy conversion systems in {jurisdiction}?']#
List of search engine query templates for extraction
- Type:
- WEBSITE_KEYWORDS = {'area': 60, 'code': 60, 'department': 1, 'energy': 3, 'environment': 3, 'government': 180, 'land': 3, 'land development': 15, 'land%20development': 15, 'land+development': 15, 'municipal': 1, 'ordinance': 5760, 'pdf': 92160, 'plan': 360, 'planning': 720, 'renewable': 3, 'renewable energy': 1440, 'renewable%20energy': 1440, 'renewable+energy': 1440, 'wecs': 46080, 'wind': 23040, 'zoning': 11520}#
List of keywords
Keywords indicate links which should be prioritized when performing a website scrape for a wind ordinance document.
- Type:
- HEURISTIC#
BaseHeuristic: Class with a
check()methodalias of
WindHeuristic
- JURISDICTION_DATA_FP = None#
Path to jurisdiction CSV
If provided, this CSV will extend the known jurisdictions (by default, US states, counties, and townships). This CSV must have the following columns:
State: The state in which the jurisdiction is located (e.g. “Texas”)
County: The county in which the jurisdiction is located (e.g. “Travis”). This can be left blank if the jurisdiction is not associated with a county.
Subdivision: The name of the subdivision of the county in which the jurisdiction is located. Use this input for jurisdictions that do not map to counties/townships (e.g. water conservation districts, resource management plan areas, etc.). This can be left blank if the jurisdiction does not have the notion of a “subdivision”.
Jurisdiction Type: The type of jurisdiction (e.g. “county”, “township”, “city”, “special district”, “RMP”, etc.).
FIPS: The code to be used for the jurisdiction, if applicable (e.g. “48453” for Travis County, Texas, “22” for the Culberson County Groundwater Conservation District, etc.). This can be left blank if the jurisdiction does not have an applicable code.
Website: The official website for the jurisdiction, if applicable (e.g. “https://www.traviscountytx.gov/”). This can be left blank if the jurisdiction does not have an official website or if the website is not known.
- Type:
- async extract_ordinances_from_text(doc, parser_class, model_config)#
Extract structured data from input text
The extracted structured data will be stored in the
.attrsdictionary of the input document under theparser_class.OUT_LABELkey.- Parameters:
doc (
elm.web.document.BaseDocument) – Document containing text to extract structured data from.parser_class (
BaseParser) – Class to use for structured data extraction.model_config (
LLMConfig) – Configuration for the LLM model to use for structured data extraction.
- async extract_relevant_text(doc, extractor_class, model_config)#
Condense text for extraction task
This method takes a text extractor and applies it to the collected document chunks to get a concise version of the text that can be used for structured data extraction.
The extracted text will be stored in the
.attrsdictionary of the input document under theextractor_class.OUT_LABELkey.- Parameters:
doc (
elm.web.document.BaseDocument) – Document containing text chunks to condense.extractor_class (
BaseTextExtractor) – Class to use for text extraction.model_config (
LLMConfig) – Configuration for the LLM model to use for text extraction.
- async filter_docs(extraction_context, need_jurisdiction_verification=True)#
Filter down candidate documents before parsing
- Parameters:
extraction_context (
ExtractionContext) – Context containing candidate documents to be filtered.need_jurisdiction_verification (
bool, optional) – Whether to verify that documents pertain to the correct jurisdiction. By default,True.
- Returns:
Iterableofelm.web.document.BaseDocument– Filtered documents orNoneif no documents remain.
- async get_heuristic()#
Get a BaseHeuristic instance with a check() method
The
check()method should accept a string of text and returnTrueif the text passes the heuristic check andFalseotherwise.
- async get_query_templates()#
Get a list of search engine query templates for extraction
Query templates can contain the placeholder
{jurisdiction}which will be replaced with the full jurisdiction name during the search engine query.
- classmethod get_structured_data_row_count(data_df)#
Get the number of data rows extracted from a document
- Parameters:
data_df (
pandas.DataFrameorNone) – DataFrame to check for extracted structured data.- Returns:
int– Number of data rows extracted from the document.
- async get_website_keywords()#
Get a dict of website search keyword scores
Dictionary mapping keywords to scores that indicate links which should be prioritized when performing a website scrape for a document.
- async parse_docs_for_structured_data(extraction_context)#
Parse documents to extract structured data/information
- Parameters:
extraction_context (
ExtractionContext) – Context containing candidate documents to parse.- Returns:
ExtractionContextorNone– Context with extracted data/information stored in the.attrsdictionary, orNoneif no data was extracted.
- async parse_for_structured_data(source)#
Extract all possible structured data from a document
This method is called from the default implementation of parse_single_doc_for_structured_data() for each document that passed filtering. If you overwrite
parse_single_doc_for_structured_data(), you can ignore this method.- Parameters:
source (
elm.web.document.BaseDocumentorExtractionContext) – Source to extract structured data from. Must have an .attrs attribute that contains text from which data should be extracted.- Returns:
pandas.DataFrameorNone– DataFrame containing extracted structured data, or None if no structured data were extracted.
- async parse_multi_doc_context_for_structured_data(extraction_context)#
Parse all documents to extract structured data/information
- Parameters:
extraction_context (
ExtractionContext) – Context containing candidate documents to parse. The text from all documents will be concatenated to create the context for the extraction.- Returns:
ExtractionContextorNone– Context with extracted data/information stored in the.attrsdictionary, orNoneif no data was extracted.
- async parse_single_doc_for_structured_data(extraction_context)#
Parse documents one at a time to extract structured data
The first document to return some extracted data will be marked as the source and will be returned from this method.
- Parameters:
extraction_context (
ExtractionContext) – Context containing candidate documents to parse.- Returns:
ExtractionContextorNone– Context with extracted data/information stored in the.attrsdictionary, orNoneif no data was extracted.
- async post_filter_docs_hook(extraction_context)#
Post-process documents after running them through the filter
- Parameters:
extraction_context (
ExtractionContext) – Context with documents that passed the filtering step.- Returns:
ExtractionContext– Context with documents to be passed onto the parsing step.
- async pre_filter_docs_hook(extraction_context)#
Pre-process documents before running them through the filter
- Parameters:
extraction_context (
ExtractionContext) – Context with downloaded documents to process.- Returns:
ExtractionContext– Context with documents to be passed onto the filtering step.
- async record_usage()#
Persist usage tracking data when a tracker is available
- classmethod save_structured_data(doc_infos, out_dir)#
Write extracted water rights data to disk
- Parameters:
List of dictionaries containing the following keys:
”jurisdiction”: An initialized Jurisdiction object representing the jurisdiction that was extracted.
”ord_db_fp”: A path to the extracted structured data stored on disk, or
Noneif no data was extracted.
out_dir (path-like) – Path to the output directory for the data.
- Returns:
int– Number of unique jurisdictions that information was found/written for.
- TEXT_COLLECTORS = [<class 'compass.extraction.wind.ordinance.WindOrdinanceTextCollector'>, <class 'compass.extraction.wind.ordinance.WindPermittedUseDistrictsTextCollector'>]#
Classes for collecting wind ordinance text chunks from docs
- TEXT_EXTRACTORS = [<class 'compass.extraction.wind.ordinance.WindOrdinanceTextExtractor'>, <class 'compass.extraction.wind.ordinance.WindPermittedUseDistrictsTextExtractor'>]#
Class for extracting cleaned ord text from collected text
- PARSERS = [<class 'compass.extraction.wind.parse.StructuredWindOrdinanceParser'>, <class 'compass.extraction.wind.parse.StructuredWindPermittedUseDistrictsParser'>]#
Class for parsing structured ordinance data from text