-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCA-Repository-init 2021-06-08.py
135 lines (110 loc) · 4.87 KB
/
CA-Repository-init 2021-06-08.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# CA-Repository-init.py initializes the Common Approach repository
# It loads all of the ontologies and datafiles into the database
from owlready2 import *
# from crypto.Cipher import AES
import shutil
import os
import config
import Util
import Load
# file name for the Common Approach CIDS repository
path = "/Users/markfox/Dropbox/CSSE Folder/Projects/Common Approach/Repository/db/"
db = "cidsrepository.sqlite3"
dbfile = path + db
# backup current database
if os.path.exists(dbfile) :
shutil.move(dbfile, path + "Backup/" + db + "." + str(datetime.datetime.now()))
# create the CA repository database
default_world.set_backend(filename = dbfile, exclusive=False)
# load cids ontology
print("Loading CIDS ontology.")
config.cids = get_ontology("http://ontology.eil.utoronto.ca/cids/cids.owl")
config.cids.load()
#load the cids user related ontology
print("Loading CIDSREP ontology.")
config.cidsrep = default_world.get_ontology("http://ontology.eil.utoronto.ca/cids/cidsrep.owl")
config.cidsrep.load()
#load saved instances in repository
print("Loading CADR ontology.")
config.cadr = default_world.get_ontology('file:///Users/markfox/Dropbox/CSSE Folder/Projects/Common Approach/Repository/cadr.owl')
config.cadr.load()
print(list(config.cadr.individuals()))
config.org = default_world.get_namespace('http://ontology.eil.utoronto.ca/tove/organization')
# set up repository instance
config.repository = config.cidsrep.Repository(namespace=config.cadr)
config.repository.hasUser =[]
config.repository.hasOrganization =[]
# Create superuser - note that the password and email should be parameters of the script
# and not hardwired
superuser = config.cidsrep.User(namespace=config.cidsrep)
config.repository.hasUser.append(superuser)
superuser.userType = config.cidsrep.superuser
superuser.hasEmail = "[email protected]"
# encrypt password and store in superuser - not working - problem with Crypto module
# enc = AES.new('CARepository $-% key2021', AES.MODE_CBC, 'This is an IV456')
# superuser.hasPassword = enc.encrypt("sdic5!Pass-%")
superuser.hasPassword = "p"
# Create test organization
o1 = config.cids.SocialPurposeOrganization(namespace=config.cadr)
config.repository.hasOrganization.append(o1)
o1.hasLegalName = "Test Organization 1"
o1.hasImpactModel = [config.cids.ImpactMeasurement(namespace=config.cadr, forOrganization=o1,
hasName="Test Org 1 Impact Measurement Model" , hasStakeholder=[], hasDescription="Test Org1 impact Model",
hasOutcome=[], hasIndicator=[], hasImpactRisk=[], hasImpactReport=[], hasStakeholderOutcome=[])]
im = o1.hasImpactModel[0]
im.hasCharacteristic=[]
oid = config.org.OrganizationID(namespace=config.cadr)
o1.hasID = oid
oid.hasIdentifier = "TestOrg1"
oid.forOrganization = o1
ind1 = config.cids.Indicator(namespace=config.cadr, definedBy=o1)
ind1.hasName = "Poor Population Ratio"
ind1.hasDescription = "Measures the ratio of poor to city population."
ind1.forOrganization = o1
ind1.hasBaseline = None
ind1.hasThreshold = None
o1.hasImpactModel[0].hasIndicator =[ind1]
stk1 = config.cids.Stakeholder(namespace=config.cadr, forOrganization=o1)
stk1.hasDescription = "Stakeholder 1 for Org 1"
stk1.hasName = "Stakeholder 1"
stk1.hasCharacteristic = []
stk1.located_in = [config.cidsrep.locall]
o1.hasImpactModel[0].hasStakeholder =[stk1]
# Create second test organization
o2 = config.cids.SocialPurposeOrganization(namespace=config.cadr, hasLegalName = "Test Organization 2")
config.repository.hasOrganization.append(o2)
o2.hasImpactModel = [config.cids.ImpactMeasurement(namespace=config.cadr, forOrganization=o2,
hasName="Test Org 2 Impact Measurement Model", hasStakeholder=[],
hasOutcome=[], hasIndicator=[], hasImpactRisk=[], hasImpactReport=[], hasStakeholderOutcome=[],
hasCharacteristic=[])]
oid = config.org.OrganizationID(namespace=config.cadr, hasIdentifier = "TestOrg2", forOrganization = o2)
o2.hasID = oid
ind2 = config.cids.Indicator(namespace=config.cadr, definedBy=o2)
ind2.hasName = "Rich Population Ratio"
ind2.hasDescription = "Measures ratio of rich to city population."
ind2.forOrganization = o2
ind2.hasBaseline = None
ind2.hasThreshold = None
o2.hasImpactModel[0].hasIndicator =[ind2]
# Create test org user
normaluser = config.cidsrep.User(namespace=config.cadr)
config.repository.hasUser.append(normaluser)
normaluser.userType = config.cidsrep.admin
normaluser.hasEmail = "[email protected]"
normaluser.hasPassword = "p"
normaluser.forOrganization = o1
normaluser.forPerson = config.cids.Person(namespace=config.cadr, givenName="John", familyName="Smith")
print("CIDSREP final list of individuals:")
print(list(config.cidsrep.individuals()))
print("CADR final list of individuals:")
print(list(config.cadr.individuals()))
default_world.save()
# load IRIS Indicators
print("Loading IRIS")
Load.loadIRIS("IRIS Taxonomy 5.1_June2020.xlsx")
default_world.save()
# load UNSDGs
print("Loading UNSDGs")
Load.loadUNSDG("UNSDG.xlsx")
# save all to the database before exiting
default_world.save()