-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemanticSearchExample.py
More file actions
78 lines (63 loc) · 2.34 KB
/
Copy pathSemanticSearchExample.py
File metadata and controls
78 lines (63 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import ast
import json
import QueryTechnicalData.QueryFunctions as QF
import requests
'''
This file contains an example how to execute semantic search by using the functions of the QueryTechnicalData Package
---------------------------------------------------------------------------------------------------------------------
'''
'''
1.
First you need the endpoints to the Repository Server
There are two endpoint to specifiy the search for submodels and shells
'''
endpoint_sm = "https://fluid40.imd.mw.tu-dresden.de/hack4/query/submodels"
endpoint_sh = "https://fluid40.imd.mw.tu-dresden.de/hack4/query/shells"
'''
2.
Forumulate your query to define the criteria for the Technical Data Submodels you want to retrieve.
You can use the functions in QueryFunctions.py to get the query string for your specific component.
In this example, we are looking for a general pump
'''
query = QF.getPumpQuery_51_41(
EclassVersion=False,
ProductClassification = "51-41",
MaxOperatingPressure = 100,
Displacement_min= 0,
Displacement_max = 300,
Adjustable = True,
NominalRotationalSpeed_min = 0,
NominalRotationalSpeed_max = 3000
)
print(json.dumps(query, indent=4, sort_keys=True, ensure_ascii=False))
endpoint_sm.strip()
'''
3.
Send the query via POST request to the Repository and retrieve the fitting submodel-IDs.
'''
response_sm = requests.post(
url = endpoint_sm,
json = query
)
if response_sm.status_code == 200:
fitting_submodels = ast.literal_eval(str(response_sm.text))
print("Amount of fitting submodels: " + str(len(fitting_submodels)))
print(json.dumps(response_sm.json(), indent=4, ensure_ascii=False))
else:
print("Something went wrong: " + str(response_sm.status_code))
'''
4.
Now send another Query to get the Ids of the fitting shells for the submodels you retrieved in the last step.
'''
list_of_submodel_ids_str = QF.listIds(fitting_submodels).strip()
shell_query = QF.getShellsQuery(list_of_submodel_ids_str)
response_shells = requests.post(
url = endpoint_sh,
json = shell_query
)
if response_shells.status_code == 200:
fitting_shells = ast.literal_eval(str(response_shells.text))
print("Amount of fitting shells: " + str(len(fitting_shells)))
print(json.dumps(response_shells.json(), indent=4, ensure_ascii=False))
else:
print("Something went wrong: " + str(response_shells.status_code))