SearchIndividualWorkflow
What it is
- A workflow that searches ontology NamedIndividuals in a triple store using SPARQL.
- Matches against
rdfs:labelandskos:altLabel, then ranks results using fuzzy matching (thefuzz).
Public API
-
SearchIndividualWorkflowConfigurationtriple_store: ITripleStoreService: triple store service used to execute SPARQL queries.
-
SearchIndividualWorkflowParameterssearch_label: str(required): label text to search for.class_uri: Optional[str](defaultNone): if provided, restricts results to individuals of this class (?individual_uri a <class_uri>).limit: Optional[int](default10): maximum results to return (1–100).query: Optional[str](defaultNone): custom SPARQL query; if provided, it replaces the generated query.
-
SearchIndividualWorkflow(configuration: SearchIndividualWorkflowConfiguration)search_individual(parameters: SearchIndividualWorkflowParameters) -> list[dict]- Executes a SPARQL query and returns a list of dicts containing result bindings (notably
individual_uri,label) plus a computedscore(fuzzy match). - Sorts by
scoredescending and de-duplicates byindividual_uri.
- Executes a SPARQL query and returns a list of dicts containing result bindings (notably
as_tools() -> list[BaseTool]- Exposes
search_individualas a LangChainStructuredToolnamed"search_individual".
- Exposes
as_api(...) -> None- Present but does not register any routes (returns
None).
- Present but does not register any routes (returns
Configuration/Dependencies
- Requires an
ITripleStoreServiceimplementation with a.query(sparql_query: str)method returning iterablerdflib.query.ResultRow. - Uses:
rdflibresult rows (rdflib.query.ResultRow)thefuzz.fuzz.token_set_ratiofor scoringnaas_abi_core.utils.String.normalizefor normalization- LangChain (
langchain_core.tools.StructuredTool)
Usage
from naas_abi.workflows.SearchIndividualWorkflow import (
SearchIndividualWorkflow,
SearchIndividualWorkflowConfiguration,
SearchIndividualWorkflowParameters,
)
# triple_store must implement ITripleStoreService and provide .query(str) -> iterable of ResultRow
config = SearchIndividualWorkflowConfiguration(triple_store=triple_store)
wf = SearchIndividualWorkflow(config)
params = SearchIndividualWorkflowParameters(
search_label="Naas.ai",
class_uri=None,
limit=10,
)
results = wf.search_individual(params)
print(results)Using as a LangChain tool:
tool = wf.as_tools()[0]
out = tool.run(search_label="Naas.ai", limit=5)
print(out)Caveats
- The default generated SPARQL query references
owl:NamedIndividual,rdfs:label, andskos:altLabelbut does not declare prefixes; it relies on the triple store/query engine environment handling these. queryparameter fully overrides the generated SPARQL; in that case, returned bindings (and presence oflabel) depend on the custom query, which affects scoring/sorting behavior.