Data property and object property reification
Posted by manas on
URL: http://owlready.306.s1.nabble.com/Data-property-and-object-property-reification-tp2447.html
In my ontology creation . i have 2 class node and tier. i have created instances node1.1, node2.1, node1.2 and node 2.2 and for tier tier1 and tier2. i have created object properties and data properties.
in object property for example node1.2 hasUpstreamNode node1.1. i wanted to assert a data property isUnique (boolean) for example <Node2.2 hasDownStream Node2,1> isUnique True. can anybody help me how to do it please.
i have pasted my code below.
from owlready2 import *
owlready2.JAVA_EXE = "C:///Users/MohapatraMan/Downloads/Protege-5.5.0-win/Protege5.5.0/jre/bin/java.exe"
onto_path.append("/home/Projects/for_manas")
onto = get_ontology("C:///Users/MohapatraMan/Desktop/New Folder/generator_ranjan.owl").load()
#create required properties
with onto:
class hasUpstreamTIER(ObjectProperty):
domain = [onto.Tier]
range = [onto.Tier]
#inverse = onto.hasDownStreamTier
with onto:
class hasUpstreamNODE(ObjectProperty):
domain = [onto.Node]
range = [onto.Node]
#inverse = onto.hasDownStreamTier
with onto:
class hasID(DataProperty, FunctionalProperty): # Each drug has a single cost
#ontology = onto
range = [int]
domain = [onto.Node]
with onto:
class hasKPI(DataProperty, FunctionalProperty): # Each drug has a single cost
#ontology = onto
range = [int]
domain = [onto.Node]
with onto:
class isUnique(DataProperty, FunctionalProperty): # Each drug has a single cost
#ontology = onto
range = [int]
domain = [onto.Node]
number_of_tiers = int(input("How many Tier?:"))
#create an empty list for storing current and previous nodes
node_list = []
tier_list = []
previous_node_list = []
previous_tier_list = []
for i in range(number_of_tiers):
y = onto.Tier("Tier{}".format(i + 1))
print(y)
number_of_nodes = int(input("Number of nodes in Tier {}?:".format(i + 1)))
for j in range(number_of_nodes):
x = onto.Node("node{}.{}".format(j + 1, i + 1))
print('no of nodes:', x)
x.belongsToTier.append(y)
if i > 0:
for node in previous_node_list[i - 1]:
x.hasDownStreamNode.append(node)
x.belongsToTier.append(y)
if i > 0:
for tier in previous_tier_list[i - 1]:
y.hasDownStreamTier.append(tier)
node_list.append(x)
tier_list.append(y)
previous_node_list.append(node_list)
node_list = []
previous_tier_list.append(tier_list)
tier_list = []
print("previous_node_list {}".format(previous_node_list))
print("previous_tier_list {}".format(previous_tier_list))
# Assigning Upstream Tiers
iterator = 1
for i in onto.Tier.instances():
i_string = str(i).split(".")[-1]
if iterator < len(previous_tier_list): # to make sure that the last node does not have an upstream
try:
print("{} has UpstreamTier {}".format(i, previous_tier_list[iterator][0]))
i.hasUpstreamTIER.append(previous_tier_list[iterator][0])
except:
print("error")
else:
# i.hasUpstreamTier.append([])
print("{} has no upstream Tier".format(i))
iterator += 1
print("---")
# Assigning Upstream nodes
for j in onto.Node.instances():
i_string = str(j).split(".")[-1]
if int(i_string) < len(previous_node_list):
# to make sure that the last node does not have an upstream
for item in previous_node_list[int(i_string)]:
print("{} has upstream Node {}".format(j, item))
j.hasUpstreamNODE.append(item)
else:
print("{} has no upstream Node".format(j))
for Node1 in onto.Node.instances():
val = input("Enter your location: ")
val1 = [val]
Node1.hasLocation = val1
print("{} has location {} ".format(Node1, val1))
for Node1 in onto.Node.instances():
ID = input("Enter your ID: ")
Node1.hasID = int(ID)
print("{} has ID {} ".format(Node1, ID))
for Node1 in onto.Node.instances():
Kpi = input("Enter your KPI: ")
Node1.hasKPI = int(Kpi)
print("{} has hasKpi {} ".format(Node1, Kpi))
#with onto:
# sync_reasoner()
#sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)
onto.save(file="Data_Generator2.owl")
Thanks&Regards
Manas Ranjan Mohapatra