Skip to content

Instantly share code, notes, and snippets.

@vjcitn
Created November 6, 2025 10:31
Show Gist options
  • Select an option

  • Save vjcitn/5f1fd0f2fa92083f703f2a3463ecadc2 to your computer and use it in GitHub Desktop.

Select an option

Save vjcitn/5f1fd0f2fa92083f703f2a3463ecadc2 to your computer and use it in GitHub Desktop.
a reasoning demonstration produced by perplexity.ai
from owlready2 import get_ontology, onto_path, sync_reasoner
def find_terms_by_keyword(ontology, keyword):
# Simple case: search class labels and names
results = []
for cls in ontology.classes():
label = cls.label.first() if hasattr(cls, "label") and cls.label else cls.name
if keyword.lower() in label.lower():
results.append(cls)
return results
def main():
onto_path.append(".")
onto = get_ontology("edam_1.25.owl").load()
print("Running reasoner...")
sync_reasoner() # Reclassifies classes and performs inference
topic = input("Enter topic or keyword: ").strip()
matches = find_terms_by_keyword(onto, topic)
print(f"\nTerms relevant to '{topic}':")
for cls in matches:
label = cls.label.first() if hasattr(cls, "label") and cls.label else ""
print(f"- {cls.name} ({label})")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment