45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
import requests
|
|
|
|
|
|
def is_ontology_exists(uid, url):
|
|
list_ontologies = requests.get(url).json()['response']
|
|
for onto in list_ontologies:
|
|
if onto['uid'] == uid:
|
|
return False
|
|
return True
|
|
|
|
|
|
def get_list_sqwrl(uid, url):
|
|
return requests.get(url + f'{uid}/query/', verify=False).json()
|
|
|
|
|
|
def get_entity_square(results_ndarray_i):
|
|
square = float((results_ndarray_i[2] - results_ndarray_i[0]) *
|
|
(results_ndarray_i[3] - results_ndarray_i[1]))
|
|
return abs(square)
|
|
|
|
|
|
def get_request_data(entities, results_ndarray):
|
|
classroom = 'classroom'
|
|
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})
|
|
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])})
|
|
|
|
return object_properties, data_properties
|