Add support of multipart terms

This commit is contained in:
Aleksey Filippov 2023-05-16 17:23:30 +04:00
parent ee9ad0d7e5
commit 9d72c466da
6 changed files with 1537 additions and 217 deletions

10
main.py
View File

@ -12,11 +12,17 @@ from src.syntax import Syntax
def _main(wav_file: str):
text: str = Speech().run_recognition(wav_file)
# text: str = 'как получить кредит на обучение'
print(f'Text: {text}')
parse_tree: ParseTree = Syntax().get_parse_tree(text)
print(f'Parse tree:\n{parse_tree}')
terms: List[str] = NLP().get_by_template(parse_tree, ['NOUN', 'VERB', 'ADJ'])
print(f'Extracted terms:\n{" ".join(terms)}')
nlp: NLP = NLP()
terms: List[str] = []
terms.extend(nlp.get_adj_noun(parse_tree))
terms.extend(nlp.get_nouns(parse_tree))
if len(terms) == 0:
terms.extend(nlp.get_terms_by_template(parse_tree, ['NOUN', 'VERB', 'ADJ']))
print(f'Extracted terms:\n{", ".join(terms)}')
result: str = MyOntology().get_event_description(terms)
print(f'Test:\n{result}')

651
ontology-1.owl Normal file
View File

@ -0,0 +1,651 @@
<?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="" IRI="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>
<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>
<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>
<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>
<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>
<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="#Concept"/>
<NamedIndividual IRI="#Доступныерансферы"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Ежемесячный_платеж"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Как_стать_клиентом_банка"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Какая_суммаолга_поредиту"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Какого_числа_платеж_поредиту"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Какой_курс_обменаалют"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Какой_лимит_на_перевод_денег"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Курсалют"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Лимит_карты"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Лимит_на_перевод"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Лимит_на_снятие"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Лимит_на_снятие_в_банкомате"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Платеж_поредиту"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<NamedIndividual IRI="#Сколькооступныхрансферов"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Concept"/>
<NamedIndividual IRI="#Стать_клиентом_банка"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Event"/>
<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>
<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>
<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>
<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>
<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>
<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="#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="#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>
<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>
<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>
<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="#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>
<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>
<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">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">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">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">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">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">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">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>
<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>
<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 -->

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ class MyOntology:
def __find_str_in_list(self, string: str, string_list: List[str]) -> int:
try:
string_list.index(string)
string_list.index(string.replace("_", " "))
return 1
except ValueError:
return 0
@ -28,18 +28,18 @@ class MyOntology:
events.sort(key=lambda item: list(item.keys())[0], reverse=True)
return events
def __find_instances_by_terms(self, nouns: List[str]) -> []:
def __find_instances_by_terms(self, my_terms: List[str]) -> []:
instances = []
for instance in self.__onto.Concept.instances():
terms = instance.hasTerm
match: int = 0
for term in terms:
match = match + self.__find_str_in_list(term.name, nouns)
match = match + self.__find_str_in_list(term.name, my_terms)
if match >= 1:
instances.append(instance)
return instances
def get_event_description(self, nouns: List[str]) -> str:
instances: [] = self.__find_instances_by_terms(nouns)
def get_event_description(self, terms: List[str]) -> str:
instances: [] = self.__find_instances_by_terms(terms)
events = self.__get_event_instance(instances)
return '\n'.join(list(map(lambda item: f'{list(item.keys())[0]}: {list(item.values())[0]}', events)))

View File

@ -1,19 +1,66 @@
from typing import List
from typing import List, Set
import ru_core_news_sm
from anytree import LevelOrderIter
from anytree import LevelOrderIter, Resolver, ChildResolverError, LevelOrderGroupIter, \
ResolverError
from src.parse_tree.parse_tree import ParseTree
from src.parse_tree.parse_tree_node import ParseTreeNode
class NLP:
@staticmethod
def __get_nodes_by_template(tree: ParseTree, template: str) -> list:
top = tree.get_tree_root()
r = Resolver('upos')
nodes: list = []
try:
nodes.extend(r.glob(top, template))
except (ChildResolverError, ResolverError):
print(f'Can\'t find some terms by template {template}')
return nodes
def __get_terms_by_template(self, tree: ParseTree, template: str) -> List[str]:
terms: Set[str] = set()
nodes: list = []
nodes.extend(self.__get_nodes_by_template(tree, f'/{template}'))
nodes.extend(self.__get_nodes_by_template(tree, template))
for node in nodes:
if node.parent is None:
continue
terms.add(f'{self.lemmatizer(node.lemma)} {self.lemmatizer(node.parent.lemma)}')
return list(terms)
def __get_terms_by_upos(self, tree: ParseTree, upos: str) -> List[str]:
terms: Set[str] = set()
for nodes in LevelOrderGroupIter(tree.get_tree_root()):
upos_terms: List[str] = []
for node in nodes:
if node.upos != upos:
continue
upos_terms.append(self.lemmatizer(node.lemma))
if len(upos_terms) < 2:
continue
terms.add(" ".join(upos_terms))
if len(terms) == 0:
print(f'Can\'t find some terms by template NOUN/./NOUN')
return list(terms)
def lemmatizer(self, text: str):
doc = ru_core_news_sm.load()(text)
tokens = [token.lemma_ for token in doc]
return ' '.join(tokens)
def get_by_template(self, tree: ParseTree, template: List[str]) -> List[str]:
def get_adj_noun(self, tree: ParseTree) -> List[str]:
return self.__get_terms_by_template(tree, 'NOUN/ADJ')
def get_nouns(self, tree: ParseTree) -> List[str]:
terms: List[str] = []
terms.extend(self.__get_terms_by_upos(tree, 'NOUN'))
terms.extend(self.__get_terms_by_template(tree, 'NOUN/NOUN'))
return terms
def get_terms_by_template(self, tree: ParseTree, template: List[str]) -> List[str]:
nouns: List[ParseTreeNode] = []
for node in LevelOrderIter(tree.get_tree_root()):
if node.upos not in template: