Add initial ontology support

This commit is contained in:
Aleksey Filippov 2022-01-25 09:53:33 +04:00
parent b59505fc25
commit 71e843801f
4 changed files with 198 additions and 1 deletions

184
ontology.owl Normal file
View File

@ -0,0 +1,184 @@
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.semanticweb.org/alalf/ontologies/2022/0/untitled-ontology-5"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="http://www.semanticweb.org/alalf/ontologies/2022/0/untitled-ontology-5">
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<Class IRI="#Concept"/>
</Declaration>
<Declaration>
<Class IRI="#Event"/>
</Declaration>
<Declaration>
<Class IRI="#Term"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasEvent"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasTerm"/>
</Declaration>
<Declaration>
<DataProperty IRI="#hasDescription"/>
</Declaration>
<Declaration>
<DataProperty IRI="#hasPriority"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Балансарты"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Вывести_балансарты"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Лимит_карты"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Сообщить_про_ограничения_карты"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#баланс"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#карта"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#лимит"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#ограничение"/>
</Declaration>
<DisjointClasses>
<Class IRI="#Concept"/>
<Class IRI="#Event"/>
<Class IRI="#Term"/>
</DisjointClasses>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Балансарты"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Вывести_балансарты"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Лимит_карты"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Term"/>
<NamedIndividual IRI="#баланс"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Term"/>
<NamedIndividual IRI="#карта"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Term"/>
<NamedIndividual IRI="#лимит"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Term"/>
<NamedIndividual IRI="#ограничение"/>
</ClassAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasEvent"/>
<NamedIndividual IRI="#Балансарты"/>
<NamedIndividual IRI="#Вывести_балансарты"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasTerm"/>
<NamedIndividual IRI="#Балансарты"/>
<NamedIndividual IRI="#баланс"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasTerm"/>
<NamedIndividual IRI="#Балансарты"/>
<NamedIndividual IRI="#карта"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasEvent"/>
<NamedIndividual IRI="#Лимит_карты"/>
<NamedIndividual IRI="#Сообщить_про_ограничения_карты"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasTerm"/>
<NamedIndividual IRI="#Лимит_карты"/>
<NamedIndividual IRI="#карта"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasTerm"/>
<NamedIndividual IRI="#Лимит_карты"/>
<NamedIndividual IRI="#лимит"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#hasTerm"/>
<NamedIndividual IRI="#Лимит_карты"/>
<NamedIndividual IRI="#ограничение"/>
</ObjectPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#hasDescription"/>
<NamedIndividual IRI="#Вывести_балансарты"/>
<Literal>Вывожу баланс карты</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#hasPriority"/>
<NamedIndividual IRI="#Вывести_балансарты"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#int">1</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#hasDescription"/>
<NamedIndividual IRI="#Сообщить_про_ограничения_карты"/>
<Literal>Сообщить про ограничения карты</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#hasPriority"/>
<NamedIndividual IRI="#Сообщить_про_ограничения_карты"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#int">5</Literal>
</DataPropertyAssertion>
<ObjectPropertyDomain>
<ObjectProperty IRI="#hasEvent"/>
<Class IRI="#Concept"/>
</ObjectPropertyDomain>
<ObjectPropertyDomain>
<ObjectProperty IRI="#hasTerm"/>
<Class IRI="#Concept"/>
</ObjectPropertyDomain>
<ObjectPropertyRange>
<ObjectProperty IRI="#hasEvent"/>
<Class IRI="#Event"/>
</ObjectPropertyRange>
<ObjectPropertyRange>
<ObjectProperty IRI="#hasTerm"/>
<Class IRI="#Term"/>
</ObjectPropertyRange>
<DataPropertyDomain>
<DataProperty IRI="#hasDescription"/>
<Class IRI="#Event"/>
</DataPropertyDomain>
<DataPropertyDomain>
<DataProperty IRI="#hasPriority"/>
<Class IRI="#Event"/>
</DataPropertyDomain>
<DataPropertyRange>
<DataProperty IRI="#hasDescription"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataPropertyRange>
<DataPropertyRange>
<DataProperty IRI="#hasPriority"/>
<Datatype abbreviatedIRI="xsd:int"/>
</DataPropertyRange>
</Ontology>
<!-- Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi -->

View File

@ -2,4 +2,5 @@ scipy==1.7.3
requests==2.27.1
anytree==2.8.0
spacy==3.2.1
https://github.com/explosion/spacy-models/releases/download/ru_core_news_sm-3.2.0/ru_core_news_sm-3.2.0.tar.gz
https://github.com/explosion/spacy-models/releases/download/ru_core_news_sm-3.2.0/ru_core_news_sm-3.2.0.tar.gz
Owlready2==0.36

View File

@ -4,6 +4,7 @@ import sys
import warnings
from src.nlp import NLP
from src.ontology import Ontology
from syntax import Syntax
if not sys.warnoptions:
@ -24,6 +25,8 @@ def _main():
print(f'Parse tree:\n{parse_tree}')
nouns = NLP().run(parse_tree)
print(f'Nouns:\n{nouns}')
onto = Ontology()
print(f'Test: {onto.run()}')
if __name__ == '__main__':

9
src/ontology.py Normal file
View File

@ -0,0 +1,9 @@
from owlready2 import get_ontology
class Ontology:
def __init__(self) -> None:
self._onto = get_ontology("file://./ontology.owl").load()
def run(self) -> str:
return self._onto.Concept