search
# Search (top-level)
Classes
class
Search
High-level search interface for querying corpus data with structural templates.
High-level search interface for querying corpus data with structural templates.
The Search class provides the `S` API object for finding patterns in annotated
text corpora. It uses a template language that allows you to specify:
- Node types (atoms) to match, e.g., `word`, `phrase`, `sentence`
- Feature constraints on nodes, e.g., `word pos=verb lemma=run`
- Structural relations between nodes via indentation and operators
- Quantifiers for optional or alternative patterns
Attributes
----------
api : Api
The corpus API providing access to features and navigation.
exe : SearchExe | None
The current search execution context after a search or study call.
perfParams : dict[str, int | float]
Performance tuning parameters for search optimization.
Examples
--------
Basic usage with the corpus API:
>>> CF = cfabric.Fabric(locations=corpus_path)
>>> api = CF.loadAll()
>>> S = api.S # The Search object
Simple search for all verbs:
>>> results = S.search('''
... word pos=verb
... ''')
Search with structural nesting (phrase containing a verb):
>>> results = S.search('''
... phrase
... word pos=verb
... ''')
See Also
--------
search : Execute a search and return results
study : Analyze a search template and prepare for execution
fetch : Retrieve results after study
showPlan : Display the search execution plan
Notes
-----
For detailed template syntax, see the search usage documentation.
The search engine uses edge spinning optimization to efficiently
narrow down the search space before retrieving results.
Attributes
| Name | Type | Description |
|---|---|---|
| api | Api | — |
| exe | SearchExe | None | — |
| perfParams | dict[(str, int | float)] | — |
| silent | str | — |
Methods
__init__(self, api: Api, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}) → NoneParameters
api: Apisilent: str
count(self, progress: int | None = None, limit: int | None = None) → NoneCounts the results, with progress messages, optionally up to a limit.
Parameters
progress: int | None= Nonelimit: int | None= None
fetch(self, limit: int | None = None, _msgCache: bool | list[Any] = False) → tuple[(tuple[(int, ...)], ...)] | set[int] | set[tuple[(int, ...)]] | Generator[(tuple[(int, ...)], None, None)] | tuple[(Any, str)] | NoneRetrieves query results, up to a limit.
Parameters
limit: int | None= None_msgCache: bool | list[Any]= False
glean(self, tup: tuple[(int, ...)]) → strRenders a single result into something human readable.
Parameters
tup: tuple[(int, ...)]
relationsLegend(self) → NoneDynamic info about the basic relations that can be used in templates.
search(self, searchTemplate: str, limit: int | None = None, sets: dict[(str, set[int])] | None = None, shallow: bool | int = False, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}, here: bool = True, _msgCache: bool | list[Any] = False) → tuple[(tuple[(int, ...)], ...)] | set[int] | set[tuple[(int, ...)]] | Generator[(tuple[(int, ...)], None, None)] | tuple[(Any, bool, list[str])] | tuple[(Any, bool, list[str], SearchExe)]Searches for combinations of nodes that together match a search template.
Parameters
searchTemplate: strlimit: int | None= Nonesets: dict[(str, set[int])] | None= Noneshallow: bool | int= Falsesilent: strhere: bool= True_msgCache: bool | list[Any]= False
showPlan(self, details: bool = False) → NoneShow the result of the latest study of a template.
Parameters
details: bool= False
study(self, searchTemplate: str, strategy: str | None = None, sets: dict[(str, set[int])] | None = None, shallow: bool | int = False, here: bool = True, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}) → NoneStudies a template to prepare for searching with it.
Parameters
searchTemplate: strstrategy: str | None= Nonesets: dict[(str, set[int])] | None= Noneshallow: bool | int= Falsehere: bool= Truesilent: str
tweakPerformance(self, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}, kwargs: Any = {}) → NoneTweak parameters that influence the search process.
Parameters
silent: strkwargs: Any= {}