Commit 17ba36dc authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

test scripts for finding main syntax from otnology

parent c53b3dfa
...@@ -47,12 +47,12 @@ CONNECTION_CHOICES = get_instances("SAO#Connection") ...@@ -47,12 +47,12 @@ CONNECTION_CHOICES = get_instances("SAO#Connection")
VERB_CHOICES = (("set","set"),("send","send"),("receive","receive"),("ingest","ingest"),("emit","emit"),("perform","perform"),("invoke","invoke"), VERB_CHOICES = (("set","set"),("send","send"),("receive","receive"),("ingest","ingest"),("emit","emit"),("perform","perform"),("invoke","invoke"),
("present","present"),("transfer","transfer"),("interact with","interact with"),("have state","have state"),("have substate","have substate"), ("present","present"),("transfer","transfer"),("interact with","interact with"),("have state","have state"),("have substate","have substate"),
("take values from","take values from"),("be composed","be composed"),("contain","contain")) ("take values from","take values from"),("be composed","be composed"),("contain","contain"))
SYSTEM_INTERFACE_CHOICES = SYSTEM_CHOICES + INTERFACE_CHOICES
SYSTEM_OR_FUNCTION_CHOICES = SYSTEM_CHOICES + FUNCTION_CHOICES #test to add M
FLOW_ITEM_CHOICES = FLOW_CHOICES + ITEM_CHOICES CLASS_CHOICES = (("SYSTEM","SYSTEM"), ("FUNCTION","FUNCTION"), ("SHALL","SHALL/SHALL NOT"),
SYSTEM_FUNCTION_INTERFACE_CHOICES = SYSTEM_CHOICES + FUNCTION_CHOICES + ITEM_CHOICES ("QUANTIFIER","QUANTIFIER"), ("NUMBER_UNITS","NUMBER_UNITS"), ("ITEM","ITEM"),
FLOW_FUNCTION_INTERFACE_ITEM_SYSTEM_STATE_CHOICES = FLOW_CHOICES + FUNCTION_CHOICES + INTERFACE_CHOICES + ITEM_CHOICES + SYSTEM_CHOICES + STATE_CHOICES ("STATE_VALUE","STATE_VALUE"), ("STATE","STATE"), ("STATE_SET","STATE_SET"),
ITEM_FLOW_FUNCTION = ITEM_CHOICES + FLOW_CHOICES + FUNCTION_CHOICES ("FLOW","FLOW"), ("INTERFACE","INTERFACE"), ("CONNECTION","CONNECTION"), ("VERB","VERB") )
def create_main(instance): def create_main(instance):
......
from rdflib import Graph from rdflib import Graph, BNode
from rdflib.namespace import RDFS from rdflib.namespace import RDFS
from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace from rdflib import ConjunctiveGraph, URIRef, RDFS, RDF, Namespace
...@@ -17,18 +17,120 @@ file2 = open(r"instances.txt","w+") ...@@ -17,18 +17,120 @@ file2 = open(r"instances.txt","w+")
g = Graph() g = Graph()
g.load("../Ontologies/Mokos_18_1_7_47.ttl", format="turtle") g.load("../Ontologies/Mokos_18_1_7_47.ttl", format="turtle")
#EAGLEYE cannot find
for subj, obj in g.subject_objects(predicate=RDFS.subClassOf): for subj, obj in g.subject_objects(predicate=RDFS.subClassOf):
subClass = subj + "$"+ obj + "\n" subClass = subj + "$"+ obj + "\n"
#print(subClass)
file2.write(subClass) file2.write(subClass)
l = get_instances("SAO#StateSet")
print(l)
for i in l: '''Find Boilerplate subject of each main'''
p = URIRef("http://delab.csd.auth.gr/ontologies/2018/SAO#StateSet") def get_subjects(bnodes_uriref):
for s, p, o in g.triples((None, RDF.type, p)): setOfElems = set()
print(s) duplicate_uri = []
bnodes = []
rdf_syntax = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
for elem in range (len(bnodes_uriref)):
if bnodes_uriref[elem] in setOfElems:
duplicate_uri.append(bnodes_uriref[elem])
else:
setOfElems.add(bnodes_uriref[elem])
if rdf_syntax == str(bnodes_uriref[elem]) :
bnodes = bnodes_uriref[:elem]
try:
duplicate_uri.remove(URIRef(rdf_syntax))
except:
pass
subject_list = []
for i in duplicate_uri:
if i in bnodes:
spliter = str(i).split("#")
subject_list.append(spliter[1])
return(subject_list)
'''Find Boilerplate classes between subject and verb'''
def get_related_to_subject(bnodes_uriref):
related_to_subject_list = []
bnodes_uriref = [str(i) for i in bnodes_uriref]
for rel_to_sub in bnodes_uriref:
if "isRelatedToSubject" in rel_to_sub:
tmp = rel_to_sub.split("isRelatedToSubject")
if tmp[1] != '':
related_to_subject_list.append(tmp[1])
return(related_to_subject_list)
'''Find Boilerplate Verb'''
def get_verb(bnodes_uriref):
verb_list = []
bnodes_uriref = [str(i) for i in bnodes_uriref]
for rel_to_sub in bnodes_uriref:
if "LO" in rel_to_sub:
tmp = rel_to_sub.split("#")
if tmp[1] != '':
verb_list.append(tmp[1])
return(verb_list)
'''Check if Boilerplate has quantifier'''
def check_quantifier(bnodes_uriref):
bnodes_uriref = [str(i) for i in bnodes_uriref]
quantity = [(rel_to_sub) for rel_to_sub in bnodes_uriref if "isRelatedToQuantity" in rel_to_sub]
uom = [(rel_to_sub) for rel_to_sub in bnodes_uriref if "isRelatedtoUOM" in rel_to_sub]
if quantity and uom:
return True
'''Find Main syntax - return a dict with the syntax'''
get_main = get_instances("RBO#Main")
for main in get_main:
bnodes = []
p = URIRef("http://delab.csd.auth.gr/ontologies/2018/RBO#" + main)
for s, p, o in g.triples((p, None, None)):
if isinstance(o, BNode):
bnodes.append(o)
bnodes.sort()
for bn in bnodes:
for objects in g.objects(subject=BNode(bn)):
if isinstance(objects, BNode):
bnodes.append(objects)
bnodes.sort()
bnodes_uriref = []
for bn in bnodes:
for objects in g.objects(subject=BNode(bn)):
if isinstance(objects, URIRef):
bnodes_uriref.append(objects)
subjects = get_subjects(bnodes_uriref)
related_subjects = get_related_to_subject(bnodes_uriref)
#print(get_verb(bnodes_uriref))
#print(check_quantifier(bnodes_uriref))
## FIND attribute
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment