|
|
|
@ -15,41 +15,49 @@ def is_ontology_exists(uid: str, url: str) -> bool:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_entity_square(results_ndarray_i: np.ndarray) -> float:
|
|
|
|
|
def rename_entity(list_names: dict) -> dict:
|
|
|
|
|
'''
|
|
|
|
|
Нормализация названий объектов.
|
|
|
|
|
@param list_names: Список названий объектов.
|
|
|
|
|
'''
|
|
|
|
|
temp_list = list()
|
|
|
|
|
for entity in list_names.values():
|
|
|
|
|
entity: str
|
|
|
|
|
temp_list.append(entity.title().replace(' ', ''))
|
|
|
|
|
return temp_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_entity_square(width: float, height: float) -> float:
|
|
|
|
|
'''
|
|
|
|
|
Получение площади занимаемой области.
|
|
|
|
|
@param results_ndarray_i: Описание местоположения объекта.
|
|
|
|
|
@param width: Ширина области в px.
|
|
|
|
|
@param height: Высота области в px.
|
|
|
|
|
'''
|
|
|
|
|
square = float((results_ndarray_i[2] - results_ndarray_i[0]) *
|
|
|
|
|
(results_ndarray_i[3] - results_ndarray_i[1]))
|
|
|
|
|
return abs(square)
|
|
|
|
|
return abs(width * height)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_request_data(entities: dict, results_ndarray: np.ndarray) -> tuple[list, list]:
|
|
|
|
|
def get_request_data(entities: dict, objects: np.ndarray, confs: np.ndarray, boxes: np.ndarray) -> tuple[list, list]:
|
|
|
|
|
'''
|
|
|
|
|
Формирование данных для сервиса онтологий.
|
|
|
|
|
@param entities: Список имён объектов.
|
|
|
|
|
@param results_ndarray: Результат распознавания объектов.
|
|
|
|
|
'''
|
|
|
|
|
classroom = 'classroom'
|
|
|
|
|
entities = rename_entity(entities)
|
|
|
|
|
object_properties = list()
|
|
|
|
|
data_properties = list()
|
|
|
|
|
for i, entity in enumerate(entities): # запись в лист имен объектов и присутствие
|
|
|
|
|
if (results_ndarray[:, -1] == i).sum() > 0: # если объект найден
|
|
|
|
|
object_properties.append({'domain': entity,
|
|
|
|
|
'property': 'locatedIn',
|
|
|
|
|
'range': classroom})
|
|
|
|
|
|
|
|
|
|
for entity_idx, entity in enumerate(entities):
|
|
|
|
|
if (entity_idx in objects):
|
|
|
|
|
object_properties.append({'domain': entity, 'property': 'locatedIn', 'range': classroom})
|
|
|
|
|
else:
|
|
|
|
|
object_properties.append({'domain': entity,
|
|
|
|
|
'property': 'notLocatedIn',
|
|
|
|
|
'range': classroom})
|
|
|
|
|
|
|
|
|
|
for i in range(results_ndarray.shape[0]):
|
|
|
|
|
data_properties.append({'domain': entities[int(results_ndarray[i, 5])],
|
|
|
|
|
'property': 'hasArea',
|
|
|
|
|
'value': get_entity_square(results_ndarray[i])})
|
|
|
|
|
data_properties.append({'domain': entities[int(results_ndarray[i, 5])],
|
|
|
|
|
'property': 'hasConfidence',
|
|
|
|
|
'value': float(results_ndarray[i, 4])})
|
|
|
|
|
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)})
|
|
|
|
|
|
|
|
|
|
return object_properties, data_properties
|
|
|
|
|