Skip to content

Commit

Permalink
Merge branch 'lazaroDevelop' of https://github.com/feup-infolab/archg…
Browse files Browse the repository at this point in the history
…raph into lazaroDevelop
  • Loading branch information
silvae86 committed May 27, 2020
2 parents 56e386c + 830592d commit 7cf53f6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/Models/CRM/v5_0_2/NodeEntities/E1_CRM_Entity.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from marshmallow import Schema, fields
from neomodel import (
One,
RelationshipTo,
StringProperty,
StructuredNode,
UniqueIdProperty,
db, ZeroOrOne,
ZeroOrOne,
)
from src.GCF.decorators.OntologyClass import ontology_class, decorator_schema
from src.Models.CRM.v5_0_2.NodeProperties.has_value import has_value
Expand All @@ -32,7 +31,7 @@ class E1_CRM_EntitySchema(Schema):
P137_exemplifies = fields.List(fields.Nested("src.Models.CRM.v5_0_2.NodeEntities.E55_Type.E55_TypeSchema"))
P48_has_preferred_identifier = fields.Nested("src.Models.CRM.v5_0_2.NodeEntities.E42_Identifier.E42_IdentifierSchema")
P139_has_alternative_form = fields.List(fields.Nested("src.Models.CRM.v5_0_2.NodeEntities.E41_Appellation.E41_AppellationSchema"))
P1_is_identified_by = fields.Nested("src.Models.CRM.v5_0_2.NodeEntities.E55_Type.E55_TypeSchema")
P1_is_identified_by = fields.Nested("src.Models.CRM.v5_0_2.NodeEntities.E41_Appellation.E41_AppellationSchema")
has_value = fields.List(
fields.Nested("src.Models.DataObject.v0_0_2.DataObject.DataObjectSchema")
)
Expand Down
49 changes: 22 additions & 27 deletions src/Models/DataObject/v0_0_2/SuperClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class SuperClass:
def __init__(self, schema):
self.schema = schema

"""The function returns the node schema"""
def getSchema(self):
json_schema = JSONSchema()
return json_schema.dump(self.schema)

# Json to string
"""The function returns the node information in string"""
def encodeJSON(self):
data = {}
for key, val in self.__properties__.items():
Expand All @@ -24,18 +25,21 @@ def my_converter(o):

return json.dumps(data, default=my_converter)

# string to json
"""The function returns the node information at format json"""
def decodeJSON(self):
return json.loads(self.encodeJSON())

"""The function returns the property of entity with name property_name"""
def get_property_from_entity(self, property_name):
schema_node = self.getSchema()
class_name = self.__class__.__name__ + "Schema"
return schema_node['definitions'][class_name]['properties'][property_name]

"""The function returns its superclasses names"""
def get_superclasses_name(self):
return list(set(self.labels()))

"""The function returns the schema according to the template provided"""
def get_schema_with_template(self, template):
jsonSchema = self.getSchema()
newJsonSchema = {
Expand All @@ -46,6 +50,7 @@ def get_schema_with_template(self, template):
self.__get_schema_with_template_aux(jsonSchema["definitions"], template, newJsonSchema)
return newJsonSchema

"""Auxiliary function - The function returns the schema according to the template provided"""
def __get_schema_with_template_aux(self, definitions, json_template, new_json_schema):
if isinstance(json_template, str):
entity_name = json_template
Expand Down Expand Up @@ -97,6 +102,7 @@ def __get_entity_properties_without_ref(self, current_entity, entity):
# 'type': 'string'}
# changed_property['title'] = property_entity['title']

"""The function merges between node and customer data, then saves the node"""
def merge_node(self, updated_node):
merged_node = dict(self.decodeJSON(), **updated_node)
field_type_date = self.__get_field_of_type_date()
Expand All @@ -111,30 +117,26 @@ def merge_node(self, updated_node):
self.save()
except BaseException:
return None

# array_uid = read_relationships(node_name, relationship_name)
#
# for uid in array_uid:
# node = get_node_by_uid(uid)

return True

def node_self_build(self, updated_node):
object = {'self_node': {},
"""The function returns the node with updated fields and relationships"""
def build_node(self, data):
node = {'self_node': {},
'relationships': {}}
for property in updated_node.keys():
if isinstance(updated_node[property], str):
object['self_node'][property] = updated_node[property]
elif isinstance(updated_node[property], dict):
object['relationships'][property] = []
object['relationships'][property].append(updated_node[property])
elif isinstance(updated_node[property], list):
for property in data.keys():
if isinstance(data[property], str):
node['self_node'][property] = data[property]
elif isinstance(data[property], dict):
node['relationships'][property] = []
node['relationships'][property].append(data[property])
elif isinstance(data[property], list):
relationships = []
for element in updated_node[property]:
for element in data[property]:
relationships.append(element)
object['relationships'][property] = relationships
return object
node['relationships'][property] = relationships
return node

"""The function returns entity's fields of type date"""
def __get_field_of_type_date(self):
result = []
get_schema = self.getSchema()
Expand All @@ -146,10 +148,3 @@ def __get_field_of_type_date(self):
result.append(field["title"])
return result

# def get_labels(target, base_class):
# return (
# c.__name__
# for c in target.__mro__
# if issubclass(c, base_class)
# )

2 changes: 1 addition & 1 deletion src/Utils/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def updated_node(node, data, template):

# auxiliary function - given a template and a node, the node and next nodes information is updated
def updated_node_aux(current_node, data, template):
new_node = current_node.node_self_build(data)
new_node = current_node.build_node(data)
if current_node.merge_node(new_node['self_node']):
for relationship_name in template:
relationship_of_node = getattr(current_node, relationship_name)
Expand Down

0 comments on commit 7cf53f6

Please sign in to comment.