|
|
|
@ -11,13 +11,39 @@ def is_ontology_exists(ontology_uid: str, url: str) -> bool:
|
|
|
|
|
@param ontology_uid: УИД онтологии.
|
|
|
|
|
@param url: Базовый URL сервиса.
|
|
|
|
|
'''
|
|
|
|
|
list_ontologies = requests.get(url).json()['response']['items']
|
|
|
|
|
list_ontologies = requests.get(url).json()
|
|
|
|
|
list_ontologies = list_ontologies['response']['items']
|
|
|
|
|
for onto in list_ontologies:
|
|
|
|
|
if onto['uid'] == ontology_uid:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upload_ontology(name: str, file_buf) -> str:
|
|
|
|
|
"""
|
|
|
|
|
Загружает файл.
|
|
|
|
|
:param name: Имя файла.
|
|
|
|
|
:param file_buf: Содержимое файла.
|
|
|
|
|
:return: УИД загруженной онтологии.
|
|
|
|
|
"""
|
|
|
|
|
files = {'file': file_buf}
|
|
|
|
|
response = requests.post(f'{url}?name={name}', files=files)
|
|
|
|
|
response = response.json()
|
|
|
|
|
return response['response']['uid']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_ontology(ontology_uid: str) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
Загружает файл.
|
|
|
|
|
:param name: Имя файла.
|
|
|
|
|
:param file_buf: Содержимое файла.
|
|
|
|
|
:return: УИД загруженной онтологии.
|
|
|
|
|
"""
|
|
|
|
|
response = requests.delete(url + ontology_uid)
|
|
|
|
|
response = response.json()
|
|
|
|
|
return False if response['error'] else True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rename_entity(list_names: dict) -> dict:
|
|
|
|
|
'''
|
|
|
|
|
Нормализация названий объектов.
|
|
|
|
@ -52,16 +78,24 @@ def get_request_data(entities: dict, objects: np.ndarray, confs: np.ndarray, box
|
|
|
|
|
|
|
|
|
|
for entity_idx, entity in enumerate(entities):
|
|
|
|
|
if (entity_idx in objects):
|
|
|
|
|
object_properties.append({'domain': entity, 'property': 'locatedIn', 'range': classroom})
|
|
|
|
|
object_properties.append(
|
|
|
|
|
{'domain': entity, 'property': 'locatedIn', 'range': classroom})
|
|
|
|
|
else:
|
|
|
|
|
object_properties.append({'domain': entity, 'property': 'notLocatedIn', 'range': classroom})
|
|
|
|
|
object_properties.append(
|
|
|
|
|
{'domain': entity, 'property': 'notLocatedIn', 'range': classroom})
|
|
|
|
|
|
|
|
|
|
for object_idx, object in enumerate(objects):
|
|
|
|
|
conf = confs[object_idx]
|
|
|
|
|
box = boxes[object_idx]
|
|
|
|
|
entity = entities[object.item()]
|
|
|
|
|
data_properties.append({'domain': entity, 'property': 'hasArea', 'value': get_entity_square(float(box[2]), float(box[3]))})
|
|
|
|
|
data_properties.append({'domain': entity, 'property': 'hasConfidence', 'value': float(conf)})
|
|
|
|
|
data_properties.append(
|
|
|
|
|
{'domain': entity,
|
|
|
|
|
'property': 'hasArea',
|
|
|
|
|
'value': get_entity_square(float(box[2]), float(box[3]))})
|
|
|
|
|
data_properties.append(
|
|
|
|
|
{'domain': entity,
|
|
|
|
|
'property': 'hasConfidence',
|
|
|
|
|
'value': float(conf)})
|
|
|
|
|
|
|
|
|
|
return object_properties, data_properties
|
|
|
|
|
|
|
|
|
@ -86,8 +120,9 @@ def analyze(ontology_uid: str, object_properties: list, data_properties: list, q
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
params = '&'.join([f'names={query}' for query in queries])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Выполнение запроса.
|
|
|
|
|
response = requests.post(url + f'{ontology_uid}/query/multi?{params}', json=data).json()
|
|
|
|
|
|
|
|
|
|
response = requests.post(
|
|
|
|
|
url + f'{ontology_uid}/query/multi?{params}', json=data).json()
|
|
|
|
|
|
|
|
|
|
return response
|
|
|
|
|