Main class for natural language to SPARQL conversion.
KBQueryEngine(ontology_path: str, config_path: Optional[str] = None)Parameters:
ontology_path: Path to OWL/RDF ontology file (Turtle format)config_path: Optional path to YAML configuration file
Convert natural language query to SPARQL.
Parameters:
natural_language_query: Query in natural language
Returns: Dictionary containing:
sparql: Generated SPARQL queryparsed: Parsed query componentsresults: Query results (if endpoint configured)
Example:
result = engine.query("meetings with John Smith")
print(result['sparql'])Get all query patterns available for a class.
Parameters:
class_name: Name of the ontology class
Returns: List of example queries for the class
Get query suggestions for partial input.
Parameters:
partial: Partial query string
Returns: List of suggested complete queries
Base exception for all KB Query errors.
Raised when ontology parsing fails.
Raised when natural language query cannot be parsed.
Attributes:
suggestions: List of similar valid queries