From 4d355aa1b3891fc47ce89ba48ff3ba6d27e4ecc1 Mon Sep 17 00:00:00 2001 From: valexande Date: Thu, 10 Oct 2024 22:59:05 +0000 Subject: [PATCH] Upload files to "ifcParser" --- ifcParser/ifcGeometricContext.py | 50 + ifcParser/ifcJsonParser.py | 3395 ++++++++++++++++++++++++++++++ ifcParser/ifcProject.py | 146 ++ ifcParser/ifcShape.py | 327 +++ ifcParser/main-mapping.py | 25 + 5 files changed, 3943 insertions(+) create mode 100644 ifcParser/ifcGeometricContext.py create mode 100644 ifcParser/ifcJsonParser.py create mode 100644 ifcParser/ifcProject.py create mode 100644 ifcParser/ifcShape.py create mode 100644 ifcParser/main-mapping.py diff --git a/ifcParser/ifcGeometricContext.py b/ifcParser/ifcGeometricContext.py new file mode 100644 index 0000000..2ad02f4 --- /dev/null +++ b/ifcParser/ifcGeometricContext.py @@ -0,0 +1,50 @@ +from rdflib import Graph, Namespace, URIRef, Literal, RDF, RDFS, XSD + + +class geometric(): + + def __init__(self, IfcGeometricRepresentationSubContext, g, ontology, resource): + self.IfcGeometricRepresentationSubContext = IfcGeometricRepresentationSubContext + self.g = g + self.ontology = ontology + self.resource = resource + + def ifcGeometricRepresentationSubContextFunction(self): + for context in self.IfcGeometricRepresentationSubContext: + contextID = context['globalId'] + #basic information + self.g.add((self.resource[contextID], RDF.type, self.ontology.Context)) + try: # contextIdentifier is not always there + contextIdentifier = context['contextIdentifier'] + self.g.add((self.resource[contextID], self.ontology.identifier, Literal(contextIdentifier))) + except Exception: + pass + try: # contextType is not always there + contextType = context['contextType'] + self.g.add((self.resource[contextID], self.ontology.contextType, Literal(contextType))) + except Exception: + pass + try: # targetView is not always there + contextTargetView = context['targetView'] + self.g.add((self.resource[contextID], self.ontology.targetView, Literal(contextTargetView))) + except Exception: + pass + try: # contextType is not always there + parentContext = context['parentContext']['ref'] + self.g.add((self.resource[parentContext], RDF.type, self.ontology.Context)) + self.g.add((self.resource[contextID], self.ontology.hasParentContext, self.resource[parentContext])) + except Exception: + pass + + try: # contextType is not always there + for element in context['representationsInContext']: + if "ref" in list(element.keys()): + self.g.add((self.resource[element['ref']], RDF.type, self.ontology.Context)) + self.g.add((self.resource[contextID], self.ontology.hasRelatedContext, self.resource[element['ref']])) + except Exception: + pass + + # Create RDF triples + # Serialize and save the RDF graph to a TTL file + file_path = "output.ttl" + self.g.serialize(destination=file_path, format="turtle") \ No newline at end of file diff --git a/ifcParser/ifcJsonParser.py b/ifcParser/ifcJsonParser.py new file mode 100644 index 0000000..bb8cb6b --- /dev/null +++ b/ifcParser/ifcJsonParser.py @@ -0,0 +1,3395 @@ +import json, sys +from flask import Flask, request, jsonify +from ifcProject import project +from ifcShape import shape +from ifcGeometricContext import geometric +from rdflib import Graph, Namespace, URIRef, Literal, RDF, RDFS, XSD +from rdflib import Graph +from SPARQLWrapper import SPARQLWrapper, POST, BASIC, URLENCODED + +# Create a new RDF graph +g = Graph() +# Define a custom namespace +ontology = Namespace("http://sincere.org/s1#") +resource = Namespace("http://sincere.org/s1/resource/") +g.bind('sincere', ontology) + +def jsonReader(): + # Open the JSON file for reading + with open('models/pipes.json', 'r') as file: + # Load the JSON data + ifcJson = json.load(file) + + return ifcJson + +def parser(ifcJson): + timestamp, schemaIdentifier, originatingSystem, preprocessorVersion = ifcJson["timeStamp"], ifcJson["schemaIdentifier"], ifcJson["originatingSystem"], ifcJson["preprocessorVersion"] + + IfcBuildingStorey, IfcRelDefinesByType, IfcBeamType, IfcRelFillsElement, IfcDoor, IfcOwnerHistory, ifcSlabType, IfcRelContainedInSpatialStructure, IfcRelAssociatesMaterial, \ + IfcBuilding, IfcColumnType, IfcColumn, IfcMemberType, IfcSite, IfcOpeningElement, IfcRelAggregates, IfcGeometricRepresentationContext, IfcWindowLiningProperties, IfcRelVoidsElement, \ + IfcDoorType, IfcGeometricRepresentationSubContext, IfcDoorLiningProperties, IfcRelDefinesByProperties, IfcWallType, IfcWindowType, IfcWall, IfcWindow, IfcGroup, IfcRelAssignsToGroup, \ + IfcProject, IfcPropertySet, IfcSlab, IfcDoorPanelProperties, IfcMember, IfcElementQuantity, IfcBeam, IfcShapeRepresentation \ + = [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [] + + types = [] + for data in ifcJson["data"]: + types.append(data['type']) + if data['type'] == "IfcBuildingStorey": + IfcBuildingStorey.append(data) + elif data['type'] == "IfcRelDefinesByType": + IfcRelDefinesByType.append(data) + elif data['type'] == "IfcBeamType": + IfcBeamType.append(data) + elif data['type'] == "IfcRelFillsElement": + IfcRelFillsElement.append(data) + elif data['type'] == "IfcDoor": + IfcDoor.append(data) + elif data['type'] == "IfcOwnerHistory": + IfcOwnerHistory.append(data) + elif data['type'] == "IfcSlabType": + ifcSlabType.append(data) + elif data['type'] == "IfcRelContainedInSpatialStructure": + IfcRelContainedInSpatialStructure.append(data) + elif data['type'] == "IfcRelAssociatesMaterial": + IfcRelAssociatesMaterial.append(data) + elif data['type'] == "IfcBuilding": + IfcBuilding.append(data) + elif data['type'] == "IfcColumnType": + IfcColumnType.append(data) + elif data['type'] == "IfcColumn": + IfcColumn.append(data) + elif data['type'] == "IfcMemberType": + IfcMemberType.append(data) + elif data['type'] == "IfcSite": + IfcSite.append(data) + elif data['type'] == "IfcOpeningElement": + IfcOpeningElement.append(data) + elif data['type'] == "IfcRelAggregates": + IfcRelAggregates.append(data) + elif data['type'] == "IfcGeometricRepresentationContext": + IfcGeometricRepresentationContext.append(data) + elif data['type'] == "IfcWindowLiningProperties": + IfcWindowLiningProperties.append(data) + elif data['type'] == "IfcRelVoidsElement": + IfcRelVoidsElement.append(data) + elif data['type'] == "IfcDoorType": + IfcDoorType.append(data) + elif data['type'] == "IfcGeometricRepresentationSubContext": + IfcGeometricRepresentationSubContext.append(data) + elif data['type'] == "IfcDoorLiningProperties": + IfcDoorLiningProperties.append(data) + elif data['type'] == "IfcRelDefinesByProperties": + IfcRelDefinesByProperties.append(data) + elif data['type'] == "IfcWallType": + IfcWallType.append(data) + elif data['type'] == "IfcWindowType": + IfcWindowType.append(data) + elif data['type'] == "IfcWall": + IfcWall.append(data) + elif data['type'] == "IfcWindow": + IfcWindow.append(data) + elif data['type'] == "IfcGroup": + IfcGroup.append(data) + elif data['type'] == "IfcRelAssignsToGroup": + IfcRelAssignsToGroup.append(data) + elif data['type'] == "IfcProject": + IfcProject.append(data) + elif data['type'] == "IfcPropertySet": + IfcPropertySet.append(data) + elif data['type'] == "IfcSlab": + IfcSlab.append(data) + elif data['type'] == "IfcDoorPanelProperties": + IfcDoorPanelProperties.append(data) + elif data['type'] == "IfcMember": + IfcMember.append(data) + elif data['type'] == "IfcElementQuantity": + IfcElementQuantity.append(data) + elif data['type'] == "IfcBeam": + IfcBeam.append(data) + elif data['type'] == "IfcShapeRepresentation": + IfcShapeRepresentation.append(data) + + return IfcBuildingStorey, IfcRelDefinesByType, IfcBeamType, IfcRelFillsElement, IfcDoor, IfcOwnerHistory, ifcSlabType, IfcRelContainedInSpatialStructure, IfcRelAssociatesMaterial,\ + IfcBuilding, IfcColumnType, IfcColumn, IfcMemberType, IfcSite, IfcOpeningElement, IfcRelAggregates, IfcGeometricRepresentationContext, IfcWindowLiningProperties, IfcRelVoidsElement, \ + IfcDoorType, IfcGeometricRepresentationSubContext, IfcDoorLiningProperties, IfcRelDefinesByProperties, IfcWallType, IfcWindowType, IfcWall, IfcWindow, IfcGroup, IfcRelAssignsToGroup, \ + IfcProject, IfcPropertySet, IfcSlab, IfcDoorPanelProperties, IfcMember, IfcElementQuantity, IfcBeam, IfcShapeRepresentation + +def ifcBuildingStoreyFunction(IfcBuildingStorey): + for building in IfcBuildingStorey: + buildingID = building['globalId'] + #basic information + g.add((resource[buildingID], RDF.type, ontology.BuildingStorey)) + try:#add history + buildingHistory = building['ownerHistory']['ref'] + g.add((resource[buildingHistory], RDF.type, ontology.History)) + g.add((resource[buildingID], ontology.hasHistory, resource[buildingHistory])) + except Exception: + pass + try:#decompose is not always there + for representation in building['decomposes']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Object)) + g.add((resource[buildingID], ontology.decomposes, resource[rep])) + except Exception: + pass + try:#definedby is not always there + for defined in building['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[buildingID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#containsElements is not always there + for representation in building['containsElements']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Structure)) + g.add((resource[buildingID], ontology.containsElements, resource[rep])) + except Exception: + pass + try:#add composition + buildingType = building['compositionType'] + g.add((resource[buildingID], ontology.composition, Literal(buildingType))) + except Exception: + pass + try:#add longName + longNameType = building['longName'] + g.add((resource[buildingID], ontology.longName, Literal(longNameType))) + except Exception: + pass + try:#add elevation + buildingElevation = building['elevation'] + g.add((resource[buildingID], ontology.elevation, Literal(buildingElevation))) + except Exception: + pass + try:#add objectType + buildingObjectType = building['objectType'] + g.add((resource[buildingID], ontology.type, Literal(buildingObjectType))) + except Exception: + pass + try:#name is not always there + buildingName = building['name'] + g.add((resource[buildingID], ontology.name, Literal(buildingName))) + except Exception: + pass + try:#name is not always there + buildingNameLong = building['longName'] + g.add((resource[buildingID], ontology.longName, Literal(buildingNameLong))) + except Exception: + pass + + try:#representationMaps data + g.add((resource[buildingID], ontology.hasPlacement, resource["plamenent_" + buildingID + "_1"])) + g.add((resource["plamenent_" + buildingID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.xlocation, Literal(building['objectPlacement']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.ylocation, Literal(building['objectPlacement']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.zlocation, Literal(building['objectPlacement']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.xaxis, + Literal(building['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.yaxis, + Literal(building['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.zaxis, + Literal(building['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.xdirection, + Literal(building['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.ydirection, + Literal(building['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.zdirection, + Literal(building['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[buildingID], ontology.hasPlacement, resource["plamenent_" + buildingID + "_2"])) + g.add((resource["plamenent_" + buildingID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.xlocation, Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.ylocation, Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.zlocation, Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.xaxis, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.yaxis, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.zaxis, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.xdirection, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.ydirection, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.zdirection, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[buildingID], ontology.hasPlacement, resource["plamenent_" + buildingID + "_3"])) + g.add((resource["plamenent_" + buildingID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.xlocation, Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.ylocation, Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.zlocation, Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.xaxis, + Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.yaxis, + Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.zaxis, + Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.xdirection, + Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.ydirection, + Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_3"], ontology.zdirection, + Literal(building['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcRelDefinesByTypeFunction(IfcRelDefinesByType): + for bytype in IfcRelDefinesByType: + bytypeID = bytype['globalId'] + #basic information + g.add((resource[bytypeID], RDF.type, ontology.Representation)) + try:#add history + bytypeHistory = bytype['ownerHistory']['ref'] + g.add((resource[bytypeHistory], RDF.type, ontology.History)) + g.add((resource[bytypeID], ontology.hasHistory, resource[bytypeHistory])) + except Exception: + pass + try: + for related in bytype['relatedObjects']: + g.add((resource[related['ref']], RDF.type, ontology.Object)) + g.add((resource[bytypeID], ontology.relatedObject, resource[related['ref']])) + except Exception: + pass + try: + g.add((resource[bytype['relatingType']['ref']], RDF.type, ontology.Representation)) + g.add((resource[bytypeID], ontology.relatingType, resource[bytype['relatingType']['ref']])) + except Exception: + pass + return 1 + +def ifcBeamTypeFunction(IfcBeamType): + for beamtype in IfcBeamType: + beamID = beamtype['globalId'] + #basic information + g.add((resource[beamID], RDF.type, ontology.BeamType)) + try:#name is not always there + beamName = beamtype['name'] + g.add((resource[beamID], ontology.name, Literal(beamName))) + except Exception: + pass + try:#name is not always there + beamPredefinedType = beamtype['predefinedType'] + g.add((resource[beamID], ontology.predefineType, Literal(beamPredefinedType))) + except Exception: + pass + try:#add history + beamOwnerHistory = beamtype['ownerHistory']['ref'] + g.add((resource[beamOwnerHistory], RDF.type, ontology.History)) + g.add((resource[beamID], ontology.hasHistory, resource[ beamOwnerHistory])) + except Exception: + pass + try:#add history + beamTag = beamtype['tag'] + g.add((resource[beamID], ontology.tag, Literal(beamTag))) + except Exception: + pass + try:#material is not always there + for material in beamtype['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[beamID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#material is not always there + for typed in beamtype['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[beamID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in beamtype['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[beamID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try:#representationMaps data + for maps in beamtype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[beamID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], RDF.type, ontology.Representation)) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xlocation, Literal(maps['mappingOrigin']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ylocation, Literal(maps['mappingOrigin']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zlocation, Literal(maps['mappingOrigin']['location']['coordinates'][2], datatype=XSD.decimal))) + + except Exception: + pass + try:#representationMaps data + for maps in beamtype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[beamID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.yaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + for maps in beamtype['representationMaps']: + + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ydirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcRelFillsElementFunction(IfcRelFillsElement): + for fills in IfcRelFillsElement: + fillsID = fills['globalId'] + #basic information + g.add((resource[fillsID], RDF.type, ontology.Object)) + try:#add history + fillsHistory = fills['ownerHistory']['ref'] + g.add((resource[fillsHistory], RDF.type, ontology.History)) + g.add((resource[fillsID], ontology.hasHistory, resource[fillsHistory])) + except Exception: + pass + try:#relatingOpeningElement is not always there + relating = fills['relatingOpeningElement']['ref'] + g.add((resource[relating], RDF.type, ontology.Opening)) + g.add((resource[fillsID], ontology.relatingOpeningElement, resource[relating])) + except Exception: + pass + try:#relatedBuildingElement is not always there + related = fills['relatedBuildingElement']['ref'] + g.add((resource[related], RDF.type, ontology.Object)) + g.add((resource[fillsID], ontology.relatedBuildingElement, resource[related])) + except Exception: + pass + return 1 + +def ifcDoorFunction(IfcDoor): + for door in IfcDoor: + doorID, doorHeight, doorWidth = door['globalId'], door['overallHeight'], door['overallWidth'] + #basic information + g.add((resource[doorID], RDF.type, ontology.Door)) + g.add((resource[doorID], ontology.height, Literal(doorHeight))) + g.add((resource[doorID], ontology.width, Literal(doorWidth))) + try:#add history + doorHistory = door['ownerHistory']['ref'] + g.add((resource[doorHistory], RDF.type, ontology.History)) + g.add((resource[doorID], ontology.hasHistory, resource[doorHistory])) + except Exception: + pass + try:#tag is not always there + doorTag = door['tag'] + g.add((resource[doorID], ontology.tag, Literal(doorTag))) + except Exception: + pass + try:#predefinedType is not always there + doorType = door['predefinedType'] + g.add((resource[doorID], ontology.predefinedType, Literal(doorType))) + except Exception: + pass + try:#operationType is not always there + doorOperation = door['operationType'] + g.add((resource[doorID], ontology.operationType, Literal(doorOperation))) + except Exception: + pass + try:#operationType is not always there + doorObject = door['objectType'] + g.add((resource[doorID], ontology.type, Literal(doorObject))) + except Exception: + pass + try:#name is not always there + doorName = door['name'] + g.add((resource[doorID], ontology.name, Literal(doorName))) + except Exception: + pass + try:#definedby is not always there + for defined in door['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[doorID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#representation is not always there + for representation in door['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Context)) + g.add((resource[doorID], ontology.hasContext, resource[rep])) + except Exception: + pass + try:#isTypedBy is not always there + for typed in door['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[doorID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#fillsVoid is not always there + for void in door['fillsVoids']: + isvoid = void['ref'] + g.add((resource[isvoid], RDF.type, ontology.Void)) + g.add((resource[doorID], ontology.fillsVoid, resource[isvoid])) + except Exception: + pass + try:#structure is not always there + for structure in door['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[doorID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#boundaries is not always there + for boundary in door['providesBoundaries']: + isboundary = boundary['ref'] + g.add((resource[isboundary], RDF.type, ontology.Boundaries)) + g.add((resource[doorID], ontology.providesBoundaries, resource[isboundary])) + except Exception: + pass + try:#decompose is not always there + for representation in door['decomposes']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Object)) + g.add((resource[doorID], ontology.decomposes, resource[rep])) + except Exception: + pass + try:#material is not always there + for material in door['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[doorID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in door['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[doorID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try: # representationMaps data + g.add((resource[doorID], ontology.hasPlacement, resource["plamenent_" + doorID + "_1"])) + g.add((resource["plamenent_" + doorID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + doorID + "_1"], ontology.xlocation, + Literal(door['objectPlacement']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.ylocation, + Literal(door['objectPlacement']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.zlocation, + Literal(door['objectPlacement']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.xaxis, + Literal(door['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.yaxis, + Literal(door['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.zaxis, + Literal(door['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.xdirection, + Literal(door['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.ydirection, + Literal(door['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_1"], ontology.zdirection, + Literal(door['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], + datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[doorID], ontology.hasPlacement, resource["plamenent_" + doorID + "_2"])) + g.add((resource["plamenent_" + doorID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + doorID + "_2"], ontology.xlocation, Literal( + door['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.ylocation, Literal( + door['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.zlocation, Literal( + door['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.xaxis, + Literal( + door['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.yaxis, + Literal( + door['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.zaxis, + Literal( + door['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.xdirection, + Literal(door['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.ydirection, + Literal(door['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_2"], ontology.zdirection, + Literal(door['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[doorID], ontology.hasPlacement, resource["plamenent_" + doorID + "_3"])) + g.add((resource["plamenent_" + doorID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + doorID + "_3"], ontology.xlocation, Literal( + door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.ylocation, Literal( + door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.zlocation, Literal( + door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.xaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.yaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.zaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.xdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.ydirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_3"], ontology.zdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[doorID], ontology.hasPlacement, resource["plamenent_" + doorID + "_4"])) + g.add((resource["plamenent_" + doorID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + doorID + "_4"], ontology.xlocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.ylocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.zlocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.xaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.yaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.zaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.xdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.ydirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_4"], ontology.zdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource[doorID], ontology.hasPlacement, resource["plamenent_" + doorID + "_5"])) + g.add((resource["plamenent_" + doorID + "_5"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + doorID + "_5"], ontology.xlocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.ylocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.zlocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.xaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.yaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.zaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.xdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.ydirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_5"], ontology.zdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource[doorID], ontology.hasPlacement, resource["plamenent_" + doorID + "_6"])) + g.add((resource["plamenent_" + doorID + "_6"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + doorID + "_6"], ontology.xlocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.ylocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.zlocation, Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.xaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.yaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.zaxis, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.xdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.ydirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + doorID + "_6"], ontology.zdirection, + Literal(door['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcOwnerHistoryFunction(IfcOwnerHistory): + for history in IfcOwnerHistory: + historyID = history['globalId'] + #basic information + g.add((resource[historyID], RDF.type, ontology.History)) + try:#creationDate is not always there + creation = history['creationDate'] + g.add((resource[historyID], ontology.creationDate, Literal(creation))) + except Exception: + pass + try:#lastModifiedDate is not always there + modified = history['lastModifiedDate'] + g.add((resource[historyID], ontology.lastModifiedDate, Literal(modified))) + except Exception: + pass + try:#changeAction is not always there + change = history['changeAction'] + g.add((resource[historyID], ontology.changeAction, Literal(change))) + except Exception: + pass + try:#changeAction is not always there + change = history['creationDate'] + g.add((resource[historyID], ontology.creationDate, Literal(change))) + except Exception: + pass + try:#state is not always there + state = history['state'] + g.add((resource[historyID], ontology.state, Literal(state))) + except Exception: + pass + try:#person is not always there + person = history['owningUser']['thePerson'] + g.add((resource["person_" + historyID], RDF.type, ontology.Person)) + g.add((resource[historyID], ontology.hasPerson, resource["person_" + historyID])) + g.add((resource["person_" + historyID], ontology.name, Literal(person['givenName']))) + except Exception: + pass + try:#organisation is not always there + organisation = history['owningUser']['theOrganization'] + g.add((resource["organisation_" + historyID], RDF.type, ontology.Organisation)) + g.add((resource[historyID], ontology.hasOrganisation, resource["organisation_" + historyID])) + g.add((resource["organisation_" + historyID], ontology.name, Literal(organisation['name']))) + except Exception: + pass + try:#application is not always there + application = history['owningApplication'] + g.add((resource["application_" + historyID], RDF.type, ontology.Application)) + g.add((resource[historyID], ontology.hasApplication, resource["application_" + historyID])) + g.add((resource["application_" + historyID], ontology.version, Literal(application['version']))) + g.add((resource["application_" + historyID], ontology.name, Literal(application['applicationFullName']))) + g.add((resource["application_" + historyID], ontology.identifier, Literal(application['applicationIdentifier']))) + + g.add((resource["developer_" + historyID], RDF.type, ontology.Developer)) + g.add((resource["application_" + historyID], ontology.hasDeveloper, resource["developer_" + historyID])) + g.add((resource["developer_" + historyID], ontology.name, Literal(application['applicationDeveloper']['name']))) + except Exception: + pass + return 1 + +def ifcSlabTypeFunction(ifcSlabType): + for slabtype in ifcSlabType: + slabID, slabPredefinedType = slabtype['globalId'], slabtype['predefinedType'] + #basic information + g.add((resource[slabID], RDF.type, ontology.SlabType)) + g.add((resource[slabID], ontology.type, Literal(slabPredefinedType))) + try:#name is not always there + slabName = slabtype['name'] + g.add((resource[slabID], ontology.name, Literal(slabName))) + except Exception: + pass + try:#name is not always there + slabPredefinedType = slabtype['predefinedType'] + g.add((resource[slabID], ontology.predefinedType, Literal(slabPredefinedType))) + except Exception: + pass + try:#add history + slabOwnerHistory = slabtype['ownerHistory']['ref'] + g.add((resource[ slabOwnerHistory], RDF.type, ontology.History)) + g.add((resource[slabID], ontology.hasHistory, resource[ slabOwnerHistory])) + except Exception: + pass + try:#add history + slabTag = slabtype['tag'] + g.add((resource[slabID], ontology.tag, resource[slabTag])) + except Exception: + pass + try:#material is not always there + for material in slabtype['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[slabID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#material is not always there + for typed in slabtype['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[slabID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in slabtype['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[slabID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try:#representationMaps data + for maps in slabtype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[slabID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], RDF.type, ontology.Representation)) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xlocation, Literal(maps['mappingOrigin']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ylocation, Literal(maps['mappingOrigin']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zlocation, Literal(maps['mappingOrigin']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.yaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ydirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcRelContainedInSpatialStructureFunction(IfcRelContainedInSpatialStructure): + for spatial in IfcRelContainedInSpatialStructure: + spatialID = spatial['globalId'] + #basic information + g.add((resource[spatialID], RDF.type, ontology.Structure)) + try:#add history + spatialHistory = spatial['ownerHistory']['ref'] + g.add((resource[spatialHistory], RDF.type, ontology.History)) + g.add((resource[spatialID], ontology.hasHistory, resource[spatialHistory])) + except Exception: + pass + try:#relatingStructure is not always there + structure = spatial['relatingStructure'] + g.add((resource[structure['ref']], RDF.type, ontology.Structure)) + g.add((resource[spatialID], ontology.relatingStructure, resource[structure['ref']])) + except Exception: + pass + try:#name is not always there + spatialName = spatial['name'] + g.add((resource[spatialID], ontology.name, Literal(spatialName))) + except Exception: + pass + try:#name is not always there + spatialDescription = spatial['description'] + g.add((resource[spatialID], ontology.description, Literal(spatialDescription))) + except Exception: + pass + try:#relatedElements is not always there + for related in spatial['relatedElements']: + element = related['ref'] + g.add((resource[element], RDF.type, ontology.Object)) + g.add((resource[spatialID], ontology.relatedElements, resource[element])) + except Exception: + pass + return 1 + +def ifcRelAssociatesMaterialFunction(IfcRelAssociatesMaterial): + for material in IfcRelAssociatesMaterial: + materialID = material['globalId'] + #basic information + g.add((resource[materialID], RDF.type, ontology.Material)) + try:#add history + materialHistory = material['ownerHistory']['ref'] + g.add((resource[materialHistory], RDF.type, ontology.History)) + g.add((resource[materialID], ontology.hasHistory, resource[materialHistory])) + except Exception: + pass + try:#name is not always there + classificationName = material['name'] + g.add((resource[materialID], ontology.name, Literal(classificationName))) + except Exception: + pass + try:#name is not always there + classificationDescription = material['description'] + g.add((resource[materialID], ontology.description, Literal(classificationDescription))) + except Exception: + pass + try:#cardinalPoint is not always there + cardinal = material['cardinalPoint'] + g.add((resource[materialID], ontology.cardinalPoint, Literal(cardinal))) + except Exception: + pass + try:#referenceExtent is not always there + extent = material['referenceExtent'] + g.add((resource[materialID], ontology.referenceExtent, Literal(extent))) + except Exception: + pass + try: # related objects + for obj in material['relatedObjects']: + propertyObject = obj['ref'] + g.add((resource[propertyObject], RDF.type, ontology.Object)) + g.add((resource[materialID], ontology.relatedObject, resource[propertyObject])) + except Exception: + pass + try:#add details of material + materialType, materialName = material['relatingMaterial']['type'], material['relatingMaterial']['name'] + g.add((resource[materialID], ontology.type, Literal(materialType))) + g.add((resource[materialID], ontology.name, Literal(materialName))) + except Exception: + pass + try:#add details of material + materialCategory = material['relatingMaterial']['category'] + g.add((resource[materialID], ontology.category, Literal(materialCategory))) + except Exception: + pass + try:#add details of material + for obj in material['relatingMaterial']['materials']: + materialType, materialName = obj['type'], obj['name'] + g.add((resource[materialID], ontology.type, Literal(materialType))) + g.add((resource[materialID], ontology.name, Literal(materialName))) + except Exception: + pass + try:#add details of material + count = 1 + for obj in material['relatingMaterial']['materialConstituents']: + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], RDF.type, ontology.MaterialConstituent)) + g.add((resource[materialID], ontology.hasConstituent, resource["constituent_" + str(materialID) + "_" + str(count)])) + if "type" in list(obj.keys()): + materialType = obj['type'] + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], ontology.type, Literal(materialType))) + if "name" in list(obj.keys()): + materialName = obj['name'] + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], ontology.name, Literal(materialName))) + if "category" in list(obj.keys()): + materialCategory = obj['category'] + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], ontology.category, Literal(materialCategory))) + if "type" in list(obj['material'].keys()): + materialType = obj['material']['type'] + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], ontology.materialType, Literal(materialType))) + if "name" in list(obj['material'].keys()): + materialName = obj['material']['name'] + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], ontology.materialName, Literal(materialName))) + if "category" in list(obj['material'].keys()): + materialCategory = obj['material']['category'] + g.add((resource["constituent_" + str(materialID) + "_" + str(count)], ontology.materialCategory, Literal(materialCategory))) + count += 1 + except Exception: + pass + try:#add details of material + if "type" in list(material["relatingMaterial"]["forProfileSet"].keys()): + materialType = material["relatingMaterial"]["forProfileSet"]['type'] + g.add((resource[materialID], ontology.profileType, Literal(materialType))) + if "name" in list(material["relatingMaterial"]["forProfileSet"].keys()): + materialName = material["relatingMaterial"]["forProfileSet"]['name'] + g.add((resource[materialID], ontology.profileName, Literal(materialName))) + for profile in material["relatingMaterial"]["forProfileSet"]["materialProfiles"]: + if "type" in list(profile["material"].keys()): + g.add((resource[materialID], ontology.materialType, Literal(profile["material"]["type"]))) + if "name" in list(profile["material"].keys()): + g.add((resource[materialID], ontology.materialName, Literal(profile["material"]["name"]))) + if "category" in list(profile["material"].keys()): + g.add((resource[materialID], ontology.materialCategory, Literal(profile["material"]["category"]))) + if "type" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.profile2Type, Literal(profile["profile"]["type"]))) + if "profileType" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.profile2Name, Literal(profile["profile"]["profileType"]))) + if "profileName" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.profileName, Literal(profile["profile"]["profileName"]))) + if "radius" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.profile2Radius, Literal(profile["profile"]["radius"]))) + if "wallThickness" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.profile2WallThickness, Literal(profile["profile"]["wallThickness"]))) + if "offsetValues" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.offSetX, Literal(profile["offsetValues"][0]))) + if "offsetValues" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.offSetY, Literal(profile["offsetValues"][1]))) + if "depth" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.depth, Literal(profile["profile"]["depth"]))) + if "flangeWidth" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.flangeWidth, Literal(profile["profile"]["flangeWidth"]))) + if "webThickness" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.webThickness, Literal(profile["profile"]["webThickness"]))) + if "flangeThickness" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.flangeThickness, Literal(profile["profile"]["flangeThickness"]))) + if "filletRadius" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.filletRadius, Literal(profile["profile"]["filletRadius"]))) + if "overallWidth" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.overallWidth, Literal(profile["profile"]["overallWidth"]))) + if "overallDepth" in list(profile["profile"].keys()): + g.add((resource[materialID], ontology.overallDepth, Literal(profile["profile"]["overallDepth"]))) + if "cardinalPoint" in list(material["relatingMaterial"].keys()): + g.add((resource[materialID], ontology.cardinalPoint, Literal(material["relatingMaterial"]["cardinalPoint"]))) + except Exception: + pass + try: + type = material['relatingMaterial']['type'] + g.add((resource[materialID], ontology.type, Literal(type))) + if "name" in list(material['relatingMaterial'].keys()): + name = material['relatingMaterial']['name'] + g.add((resource[materialID], ontology.name, Literal(name))) + for obj in material['relatingMaterial']['materialProfiles']: + type, name = obj['type'], obj['name'] + materialType, materialName = obj['material']['type'], obj['material']['name'] + g.add((resource[materialID], ontology.profileType, Literal(type))) + g.add((resource[materialID], ontology.profileName, Literal(name))) + g.add((resource[materialID], ontology.materialType, Literal(materialType))) + g.add((resource[materialID], ontology.materialName, Literal(materialName))) + profileType, profileName = obj['profile']['profileType'], obj['profile']['profileName'] + g.add((resource[materialID], ontology.profileType, Literal(profileType))) + g.add((resource[materialID], ontology.profileName, Literal(profileName))) + g.add((resource[materialID], ontology.xcoordinate, Literal(obj['profile']['position']['location']['coordinates'][0]))) + g.add((resource[materialID], ontology.ycoordinate, Literal(obj['profile']['position']['location']['coordinates'][1]))) + g.add((resource[materialID], ontology.overallWidth, Literal(obj['profile']['overallWidth']))) + g.add((resource[materialID], ontology.overallDepth, Literal(obj['profile']['overallDepth']))) + g.add((resource[materialID], ontology.webThickness, Literal(obj['profile']['webThickness']))) + g.add((resource[materialID], ontology.flangeThickness, Literal(obj['profile']['flangeThickness']))) + g.add((resource[materialID], ontology.filletRadius, Literal(obj['profile']['filletRadius']))) + if "priority" in list(obj.keys()): + g.add((resource[materialID], ontology.priority, Literal(obj['priority']))) + if "cardinalPoint" in list(obj.keys()): + g.add((resource[materialID], ontology.priority, Literal(obj['cardinalPoint']))) + except Exception: + pass + try: + type = material['relatingMaterial']['type'] + g.add((resource[materialID], ontology.type, Literal(type))) + if "name" in list(material['relatingMaterial'].keys()): + name = material['relatingMaterial']['name'] + g.add((resource[materialID], ontology.name, Literal(name))) + if "name" in list(material['relatingMaterial']['forProfileSet'].keys()): + profileType, profileName = material['relatingMaterial']['forProfileSet']['type'], material['relatingMaterial']['forProfileSet']['name'] + g.add((resource[materialID], ontology.name, Literal(profileName))) + g.add((resource[materialID], ontology.type, Literal(profileType))) + for obj in material['relatingMaterial']['forProfileSet']['materialProfiles']: + profileType, profileName = obj['profile']['profileType'], obj['profile']['profileName'] + g.add((resource[materialID], ontology.profileType, Literal(profileType))) + g.add((resource[materialID], ontology.profileName, Literal(profileName))) + g.add((resource[materialID], ontology.xcoordinate, Literal(obj['profile']['position']['location']['coordinates'][0]))) + g.add((resource[materialID], ontology.ycoordinate, Literal(obj['profile']['position']['location']['coordinates'][1]))) + g.add((resource[materialID], ontology.overallWidth, Literal(obj['profile']['overallWidth']))) + g.add((resource[materialID], ontology.overallDepth, Literal(obj['profile']['overallDepth']))) + g.add((resource[materialID], ontology.webThickness, Literal(obj['profile']['webThickness']))) + g.add((resource[materialID], ontology.flangeThickness, Literal(obj['profile']['flangeThickness']))) + g.add((resource[materialID], ontology.filletRadius, Literal(obj['profile']['filletRadius']))) + g.add((resource[materialID], ontology.priority, Literal(obj['priority']))) + except Exception: + pass + return 1 + +def ifcBuilingFunction(IfcBuilding): + for building in IfcBuilding: + buildingID = building['globalId'] + #basic information + g.add((resource[buildingID], RDF.type, ontology.Structure)) + try: + buildingHistory = building['ownerHistory']['ref'] + g.add((resource[buildingHistory], RDF.type, ontology.History)) + g.add((resource[buildingID], ontology.hasHistory, resource[buildingHistory])) + except Exception: + pass + try: + buildingObjectType = building['objectType'] + g.add((resource[buildingID], ontology.objectType, Literal(buildingObjectType))) + except Exception: + pass + try: + buildingLongName = building['longName'] + g.add((resource[buildingID], ontology.longName, Literal(buildingLongName))) + except Exception: + pass + try:#add history + buildingDescription = building['description'] + g.add((resource[buildingID], ontology.height, Literal(buildingDescription))) + except Exception: + pass + try:#name is not always there + buildingName = building['name'] + g.add((resource[buildingID], ontology.name, Literal(buildingName))) + except Exception: + pass + try:#name is not always there + addressType, addressRegion, addressCountry = building['buildingAddress']['type'], building['buildingAddress']['region'], building['buildingAddress']['country'] + g.add((resource[buildingID], ontology.addressType, Literal(addressType))) + g.add((resource[buildingID], ontology.addressRegion, Literal(addressRegion))) + g.add((resource[buildingID], ontology.addressCountry, Literal(addressCountry))) + for line in building['buildingAddress']['addressLines']: + g.add((resource[buildingID], ontology.addressLine, Literal(line))) + except Exception: + pass + try:#composition is not always there + buildingComposition = building['compositionType'] + g.add((resource[buildingID], ontology.composition, Literal(buildingComposition))) + except Exception: + pass + try:#decompose is not always there + for representation in building['isDecomposedBy']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Object)) + g.add((resource[rep], ontology.isDecomposedBy, resource[buildingID])) + except Exception: + pass + try:#decompose is not always there + for representation in building['decomposes']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Object)) + g.add((resource[buildingID], ontology.decomposes, resource[rep])) + except Exception: + pass + try:#definedby is not always there + for defined in building['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[buildingID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#definedby is not always there + for defined in building['servicedBySystems']: + servicedsystem = defined['ref'] + g.add((resource[servicedsystem], RDF.type, ontology.ServicedSystem)) + g.add((resource[buildingID], ontology.hasServicedSystem, resource[servicedsystem])) + except Exception: + pass + try: # representationMaps data + g.add((resource[buildingID], ontology.hasPlacement, resource["plamenent_" + buildingID + "_1"])) + g.add((resource["plamenent_" + buildingID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.xlocation, + Literal(building['objectPlacement']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.ylocation, + Literal(building['objectPlacement']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.zlocation, + Literal(building['objectPlacement']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.xaxis, + Literal(building['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.yaxis, + Literal(building['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.zaxis, + Literal(building['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.xdirection, + Literal(building['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.ydirection, + Literal(building['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_1"], ontology.zdirection, + Literal(building['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], + datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[buildingID], ontology.hasPlacement, resource["plamenent_" + buildingID + "_2"])) + g.add((resource["plamenent_" + buildingID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.xlocation, Literal( + building['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.ylocation, Literal( + building['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.zlocation, Literal( + building['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.xaxis, + Literal( + building['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.yaxis, + Literal( + building['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.zaxis, + Literal( + building['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.xdirection, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.ydirection, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + buildingID + "_2"], ontology.zdirection, + Literal(building['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcColumnTypeFunction(IfcColumnType): + + for columnType in IfcColumnType: + columnTypeID = columnType['globalId'] + g.add((resource[columnTypeID], RDF.type, ontology.ColumnType)) + try: # add history + columnTypeHistory = columnType['ownerHistory']['ref'] + g.add((resource[columnTypeHistory], RDF.type, ontology.History)) + g.add((resource[columnTypeID], ontology.hasHistory, resource[columnTypeHistory])) + except Exception: + pass + try: + g.add((resource[columnTypeID], ontology.name, Literal(columnType['name'].replace("\"", "")))) + except Exception: + pass + try: + g.add((resource[columnTypeID], ontology.type, Literal(columnType['predefinedType'].replace("\"", "")))) + except Exception: + pass + try: + g.add((resource[columnTypeID], ontology.tag, Literal(columnType['tag'].replace("\"", "")))) + except Exception: + pass + try:#material is not always there + for material in columnType['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[columnTypeID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#material is not always there + for typed in columnType['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[columnTypeID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in columnType['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[columnTypeID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try: # representationMaps data + g.add((resource[columnTypeID], ontology.hasPlacement, resource["plamenent_" + columnTypeID + "_1"])) + g.add((resource["plamenent_" + columnTypeID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + columnTypeID + "_1"], ontology.xlocation, + Literal(columnType['representationMaps'][0]['mappingOrigin']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnTypeID + "_1"], ontology.ylocation, + Literal(columnType['representationMaps'][0]['mappingOrigin']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnTypeID + "_1"], ontology.zlocation, + Literal(columnType['representationMaps'][0]['mappingOrigin']['location']['coordinates'][2], + datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcColumnFunction(IfcColumn): + for column in IfcColumn: + columnID = column['globalId'] + g.add((resource[columnID], RDF.type, ontology.Column)) + try: + g.add((resource[columnID], ontology.name, Literal(column['name'].replace("\"", "")))) + except Exception: + pass + try:#representation is not always there + for representation in column['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[columnID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#material is not always there + for material in column['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[columnID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#isTypedBy is not always there + for typed in column['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[columnID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#structure is not always there + for structure in column['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[columnID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#definedby is not always there + for defined in column['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[columnID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in column['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[columnID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try: # add history + columnHistory = column['ownerHistory']['ref'] + g.add((resource[columnHistory], RDF.type, ontology.History)) + g.add((resource[columnID], ontology.hasHistory, resource[columnHistory])) + except Exception: + pass + try: + g.add((resource[columnID], ontology.predefinedType, Literal(column['predefinedType'].replace("\"", "")))) + except Exception: + pass + try: + g.add((resource[columnID], ontology.name, Literal(column['name'].replace("\"", "")))) + except Exception: + pass + try: + g.add((resource[columnID], ontology.type, Literal(column['objectType'].replace("\"", "")))) + except Exception: + pass + try: + g.add((resource[columnID], ontology.tag, Literal(column['tag'].replace("\"", "")))) + except Exception: + pass + try:#representationMaps data + g.add((resource[columnID], ontology.hasPlacement, resource["plamenent_" + columnID + "_1"])) + g.add((resource["plamenent_" + columnID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + columnID + "_1"], ontology.xlocation, Literal(column['objectPlacement']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.ylocation, Literal(column['objectPlacement']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.zlocation, Literal(column['objectPlacement']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.xaxis, + Literal(column['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.yaxis, + Literal(column['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.zaxis, + Literal(column['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.xdirection, + Literal(column['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.ydirection, + Literal(column['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_1"], ontology.zdirection, + Literal(column['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[columnID], ontology.hasPlacement, resource["plamenent_" + columnID + "_2"])) + g.add((resource["plamenent_" + columnID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + columnID + "_2"], ontology.xlocation, Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.ylocation, Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.zlocation, Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.xaxis, + Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.yaxis, + Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.zaxis, + Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.xdirection, + Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.ydirection, + Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_2"], ontology.zdirection, + Literal(column['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[columnID], ontology.hasPlacement, resource["plamenent_" + columnID + "_3"])) + g.add((resource["plamenent_" + columnID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + columnID + "_3"], ontology.xlocation, Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.ylocation, Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.zlocation, Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.xaxis, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.yaxis, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.zaxis, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.xdirection, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.ydirection, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_3"], ontology.zdirection, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[columnID], ontology.hasPlacement, resource["plamenent_" + columnID + "_4"])) + g.add((resource["plamenent_" + columnID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + columnID + "_4"], ontology.xlocation, Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.ylocation, Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.zlocation, Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.xaxis, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.yaxis, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.zaxis, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.xdirection, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.ydirection, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + columnID + "_4"], ontology.zdirection, + Literal(column['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcMemberTypeFunction(IfcMemberType): + for membertype in IfcMemberType: + memberID = membertype['globalId'] + #basic information + g.add((resource[memberID], RDF.type, ontology.MemberType)) + try:#name is not always there + memberName = membertype['name'] + g.add((resource[memberID], ontology.name, Literal(memberName))) + except Exception: + pass + try:#name is not always there + memberTag = membertype['tag'] + g.add((resource[memberID], ontology.tag, Literal(memberTag))) + except Exception: + pass + try:#name is not always there + memberPredefinedType = membertype['predefinedType'] + g.add((resource[memberID], ontology.predefinedType, Literal(memberPredefinedType))) + except Exception: + pass + try:#add history + memberOwnerHistory = membertype['ownerHistory']['ref'] + g.add((resource[ memberOwnerHistory], RDF.type, ontology.History)) + g.add((resource[memberID], ontology.hasHistory, resource[ memberOwnerHistory])) + except Exception: + pass + try:#material is not always there + for material in membertype['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[memberID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in membertype['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[memberID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try:#material is not always there + for typed in membertype['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[memberID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#representationMaps data + for maps in membertype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[memberID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], RDF.type, ontology.Representation)) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xlocation, Literal(maps['mappingOrigin']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ylocation, Literal(maps['mappingOrigin']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zlocation, Literal(maps['mappingOrigin']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.yaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ydirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcSiteFunction(IfcSite): + for site in IfcSite: + siteID = site['globalId'] + #basic information + g.add((resource[siteID], RDF.type, ontology.Site)) + try:#tag is not always there + siteTag = site['objectType'] + g.add((resource[siteID], ontology.type, Literal(siteTag))) + except Exception: + pass + try:#name is not always there + siteDescription = site['description'] + g.add((resource[siteID], ontology.description, Literal(siteDescription))) + except Exception: + pass + try:#name is not always there + siteName = site['name'] + g.add((resource[siteID], ontology.name, Literal(siteName))) + except Exception: + pass + try:#add history + siteHistory = site['ownerHistory']['ref'] + g.add((resource[siteHistory], RDF.type, ontology.History)) + g.add((resource[siteID], ontology.hasHistory, resource[siteHistory])) + except Exception: + pass + try:#add composition + siteType = site['compositionType'] + g.add((resource[siteID], ontology.composition, Literal(siteType))) + except Exception: + pass + try:#add elevation + siteElevation = site['refElevation'] + g.add((resource[siteID], ontology.elevation, Literal(siteElevation))) + except Exception: + pass + try:#definedby is not always there + for defined in site['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[siteID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#representation is not always there + for representation in site['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[siteID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#decompose is not always there + for representation in site['isDecomposedBy']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Object)) + g.add((resource[rep], ontology.isDecomposedBy, resource[siteID])) + except Exception: + pass + try:#decompose is not always there + for representation in site['decomposes']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Object)) + g.add((resource[siteID], ontology.decomposes, resource[rep])) + except Exception: + pass + try:#coordinates is not always there + count = 0 + for representation in site['refLatitude']: + g.add((resource[siteID + "_" + str(count)], RDF.type, ontology.Coordinates)) + g.add((resource[siteID], ontology.hasCoordinates, resource[siteID + "_" + str(count)])) + g.add((resource[siteID + "_" + str(count)], ontology.latitude, Literal(site['refLatitude'][count], datatype=XSD.decimal))) + g.add((resource[siteID + "_" + str(count)], ontology.longitude, Literal(site['refLongitude'][count], datatype=XSD.decimal))) + count += 1 + except Exception: + pass + try:#representationMaps data + g.add((resource[siteID], ontology.hasPlacement, resource["plamenent_" + siteID])) + g.add((resource["plamenent_" + siteID], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + siteID], ontology.xlocation, Literal(site['objectPlacement']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.ylocation, Literal(site['objectPlacement']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.zlocation, Literal(site['objectPlacement']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.xaxis, + Literal(site['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.yaxis, + Literal(site['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.zaxis, + Literal(site['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.xdirection, + Literal(site['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.ydirection, + Literal(site['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + siteID], ontology.zdirection, + Literal(site['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcOpeningElementFunction(IfcOpeningElement): + for opening in IfcOpeningElement: + openingID = opening['globalId'] + #basic information + g.add((resource[openingID], RDF.type, ontology.Opening)) + try:#add history + openingHistory = opening['ownerHistory']['ref'] + g.add((resource[openingHistory], RDF.type, ontology.History)) + g.add((resource[openingID], ontology.hasHistory, resource[openingHistory])) + except Exception: + pass + try:#tag is not always there + openingTag = opening['tag'] + g.add((resource[openingID], ontology.height, Literal(openingTag))) + except Exception: + pass + try:#name is not always there + openingName = opening['name'] + g.add((resource[openingID], ontology.name, Literal(openingName))) + except Exception: + pass + try:#predefinedType is not always there + openingPredefinedType = opening['predefinedType'] + g.add((resource[openingID], ontology.predefinedType, Literal(openingPredefinedType))) + except Exception: + pass + try:#definedby is not always there + for defined in opening['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[openingID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#fillsVoidvoidsElements is not always there + for void in opening['voidsElements']: + isvoid = void['ref'] + g.add((resource[isvoid], RDF.type, ontology.Object)) + g.add((resource[openingID], ontology.voidsElements, resource[isvoid])) + except Exception: + pass + try:#representation is not always there + for representation in opening['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[openingID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in opening['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[openingID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try:#fillsVoid is not always there + for void in opening['hasFillings']: + isvoid = void['ref'] + g.add((resource[isvoid], RDF.type, ontology.Void)) + g.add((resource[openingID], ontology.fillsVoid, resource[isvoid])) + except Exception: + pass + + try:#representationMaps data + g.add((resource[openingID], ontology.hasPlacement, resource["plamenent_" + openingID + "_1"])) + g.add((resource["plamenent_" + openingID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + openingID + "_1"], ontology.xlocation, Literal(opening['objectPlacement']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.ylocation, Literal(opening['objectPlacement']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.zlocation, Literal(opening['objectPlacement']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.xaxis, + Literal(opening['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.yaxis, + Literal(opening['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.zaxis, + Literal(opening['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.xdirection, + Literal(opening['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.ydirection, + Literal(opening['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_1"], ontology.zdirection, + Literal(opening['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[openingID], ontology.hasPlacement, resource["plamenent_" + openingID + "_2"])) + g.add((resource["plamenent_" + openingID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + openingID + "_2"], ontology.xlocation, Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.ylocation, Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.zlocation, Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.xaxis, + Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.yaxis, + Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.zaxis, + Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.xdirection, + Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.ydirection, + Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_2"], ontology.zdirection, + Literal(opening['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[openingID], ontology.hasPlacement, resource["plamenent_" + openingID + "_3"])) + g.add((resource["plamenent_" + openingID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + openingID + "_3"], ontology.xlocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.ylocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.zlocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.xaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.yaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.zaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.xdirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.ydirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_3"], ontology.zdirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[openingID], ontology.hasPlacement, resource["plamenent_" + openingID + "_4"])) + g.add((resource["plamenent_" + openingID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + openingID + "_4"], ontology.xlocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.ylocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.zlocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.xaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.yaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.zaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.xdirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.ydirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_4"], ontology.zdirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource[openingID], ontology.hasPlacement, resource["plamenent_" + openingID + "_5"])) + g.add((resource["plamenent_" + openingID + "_5"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + openingID + "_5"], ontology.xlocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.ylocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.zlocation, Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.xaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.yaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.zaxis, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.xdirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.ydirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + openingID + "_5"], ontology.zdirection, + Literal(opening['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcRelAggregatesFunction(IfcRelAggregates): + for aggregates in IfcRelAggregates: + aggregatesID = aggregates['globalId'] + #basic information + g.add((resource[aggregatesID], RDF.type, ontology.Object)) + try:#add history + aggregatesHistory = aggregates['ownerHistory']['ref'] + g.add((resource[aggregatesHistory], RDF.type, ontology.History)) + g.add((resource[aggregatesID], ontology.hasHistory, resource[aggregatesHistory])) + except Exception: + pass + try:#name is not always there + aggregatesName = aggregates['name'] + g.add((resource[aggregatesID], ontology.name, Literal(aggregatesName))) + except Exception: + pass + try:#name is not always there + aggregatesDescription = aggregates['description'] + g.add((resource[aggregatesID], ontology.description, Literal(aggregatesDescription))) + except Exception: + pass + try:#relatingObject is not always there + relating = aggregates['relatingObject']['ref'] + g.add((resource[relating], RDF.type, ontology.Object)) + g.add((resource[aggregatesID], ontology.relatingElement, resource[relating])) + except Exception: + pass + try: + for related in aggregates['relatedObjects']: + g.add((resource[related['ref']], RDF.type, ontology.Object)) + g.add((resource[aggregatesID], ontology.relatedObject, resource[related['ref']])) + except Exception: + pass + return 1 + +def ifcGeometricRepresentationContextFunction(IfcGeometricRepresentationContext): + for context in IfcGeometricRepresentationContext: + contextID = context['globalId'] + #basic information + g.add((resource[contextID], RDF.type, ontology.Context)) + try:#contextType is not always there + contextType = context['contextType'] + g.add((resource[contextID], ontology.contextType, Literal(contextType))) + except Exception: + pass + try:#contextIdentifier is not always there + contextIdentifier = context['contextIdentifier'] + g.add((resource[contextID], ontology.identifier, Literal(contextIdentifier))) + except Exception: + pass + try:#precision is not always there + precision = context['precision'] + g.add((resource[contextID], ontology.contextPrecision, Literal(precision))) + except Exception: + pass + try:#coordinateSpaceDimension is not always there + space = context['coordinateSpaceDimension'] + g.add((resource[contextID], ontology.coordinateSpaceDimension, Literal(space))) + except Exception: + pass + try:#hasSubContexts is not always there + for sub in context['hasSubContexts']: + subContext = sub['ref'] + g.add((resource[subContext], RDF.type, ontology.Context)) + g.add((resource[contextID], ontology.hasSubContexts, resource[subContext])) + except Exception: + pass + try:#trueNorth is not always there + trueNorthType, trueNorthdirectionRatios0, trueNorthdirectionRatios1 = context['trueNorth']['type'], context['trueNorth']['directionRatios'][0], context['trueNorth']['directionRatios'][1] + g.add((resource[contextID], ontology.northType, Literal(trueNorthType))) + g.add((resource[contextID], ontology.northdirectionRatios0, Literal(trueNorthdirectionRatios0))) + g.add((resource[contextID], ontology.northdirectionRatios1, Literal(trueNorthdirectionRatios1))) + except Exception: + pass + try:#representationMaps data + g.add((resource["placement_" + contextID], RDF.type, ontology.Representation)) + g.add((resource[contextID], ontology.hasRepresentationType, resource["placement_" + contextID])) + g.add((resource["placement_" + contextID], ontology.xlocation, Literal(context['worldCoordinateSystem']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["placement_" + contextID], ontology.ylocation, Literal(context['worldCoordinateSystem']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["placement_" + contextID], ontology.zlocation, Literal(context['worldCoordinateSystem']['location']['coordinates'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource["placement_" + contextID], ontology.xaxis, Literal(context['worldCoordinateSystem']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["placement_" + contextID], ontology.yaxis, Literal(context['worldCoordinateSystem']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["placement_" + contextID], ontology.zaxis, Literal(context['worldCoordinateSystem']['axis']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource["placement_" + contextID], ontology.xdirection, Literal(context['worldCoordinateSystem']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["placement_" + contextID], ontology.ydirection, Literal(context['worldCoordinateSystem']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["placement_" + contextID], ontology.zdirection, Literal(context['worldCoordinateSystem']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationsInContext is not always there + for sub in context['representationsInContext']: + g.add((resource["placement_" + contextID], ontology.hasContext, + resource[sub["ref"]])) + + except Exception: + pass + return 1 + +def ifcWindowLiningPropertiesFunction(IfcWindowLiningProperties): + for window in IfcWindowLiningProperties: + windowID = window['globalId'] + #basic information + g.add((resource[windowID], RDF.type, ontology.WindowLining)) + try:#add history + windowHistory = window['ownerHistory']['ref'] + g.add((resource[windowHistory], RDF.type, ontology.History)) + g.add((resource[windowID], ontology.hasHistory, resource[windowHistory])) + except Exception: + pass + try:#name is not always there + windowName = window['name'] + g.add((resource[windowID], ontology.name, Literal(windowName))) + except Exception: + pass + try:#definedby is not always there + for defined in window['definesType']: + issdefined = defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.Representation)) + g.add((resource[windowID], ontology.hasRepresentationType, resource[issdefined])) + except Exception: + pass + try:#liningDepth is not always there + lining = window['liningDepth'] + g.add((resource[windowID], ontology.liningDepth, Literal(lining))) + except Exception: + pass + try:#liningThickness is not always there + thickness = window['liningThickness'] + g.add((resource[windowID], ontology.liningThickness, Literal(thickness))) + except Exception: + pass + return 1 + +def ifcRelVoidsElementFunction(IfcRelVoidsElement): + for void in IfcRelVoidsElement: + voidID = void['globalId'] + #basic information + g.add((resource[voidID], RDF.type, ontology.Void)) + try:#add history + voidHistory = void['ownerHistory']['ref'] + g.add((resource[voidHistory], RDF.type, ontology.History)) + g.add((resource[voidID], ontology.hasHistory, resource[voidHistory])) + except Exception: + pass + try:#relatingBuildingElement is not always there + building = void['relatingBuildingElement']['ref'] + g.add((resource[building], RDF.type, ontology.Structure)) + g.add((resource[voidID], ontology.relatingBuildingElement, resource[building])) + except Exception: + pass + try:#relatedOpeningElement is not always there + opening = void['relatedOpeningElement']['ref'] + g.add((resource[opening], RDF.type, ontology.Opening)) + g.add((resource[voidID], ontology.relatedOpeningElement, resource[opening])) + except Exception: + pass + return 1 + +def ifcDoorTypeFunction(IfcDoorType): + for doortype in IfcDoorType: + doorID = doortype['globalId'] + #basic information + g.add((resource[doorID], RDF.type, ontology.DoorType)) + try:#name is not always there + doorName = doortype['name'] + g.add((resource[doorID], ontology.name, Literal(doorName))) + except Exception: + pass + try:#predefinedType is not always there + doorPredefinedType = doortype['predefinedType'] + g.add((resource[doorID], ontology.predefinedType, Literal(doorPredefinedType))) + except Exception: + pass + try:#operationType is not always there + doorOperationType = doortype['operationType'] + g.add((resource[doorID], ontology.operationType, Literal(doorOperationType))) + except Exception: + pass + try:#add history + doorOwnerHistory = doortype['ownerHistory']['ref'] + g.add((resource[ doorOwnerHistory], RDF.type, ontology.History)) + g.add((resource[doorID], ontology.hasHistory, resource[ doorOwnerHistory])) + except Exception: + pass + try:#tag is not always there + doorTag = doortype['tag'] + g.add((resource[doorID], ontology.tag, Literal(doorTag))) + except Exception: + pass + try:#material is not always there + for material in doortype['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[doorID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in doortype['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[doorID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try: # material is not always there + for typed in doortype['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[doorID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#representationMaps data + for maps in doortype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[doorID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], RDF.type, ontology.Representation)) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xlocation, Literal(maps['mappingOrigin']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ylocation, Literal(maps['mappingOrigin']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zlocation, Literal(maps['mappingOrigin']['location']['coordinates'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcDoorLiningPropertiesFunction(IfcDoorLiningProperties): + for door in IfcDoorLiningProperties: + doorID = door['globalId'] + #basic information + g.add((resource[doorID], RDF.type, ontology.DoorLining)) + try:#add history + doorHistory = door['ownerHistory']['ref'] + g.add((resource[doorHistory], RDF.type, ontology.History)) + g.add((resource[doorID], ontology.hasHistory, resource[doorHistory])) + except Exception: + pass + try:#name is not always there + doorName = door['name'] + g.add((resource[doorID], ontology.name, Literal(doorName))) + except Exception: + pass + try:#definedby is not always there + for defined in door['definesType']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[doorID], ontology.hasProperty, resource[issdefined])) + except Exception: + pass + try:#liningDepth is not always there + lining = door['liningDepth'] + g.add((resource[doorID], ontology.liningDepth, Literal(lining))) + except Exception: + pass + try:#liningThickness is not always there + thickness = door['liningThickness'] + g.add((resource[doorID], ontology.liningThickness, Literal(thickness))) + except Exception: + pass + return 1 + +def ifcRelDefinesByPropertiesFunction(IfcRelDefinesByProperties): + for property in IfcRelDefinesByProperties: + propertyID = property['globalId'] + #basic information + g.add((resource[propertyID], RDF.type, ontology.PropertySet)) + try:#add history + propertyHistory = property['ownerHistory']['ref'] + g.add((resource[propertyHistory], RDF.type, ontology.History)) + g.add((resource[propertyID], ontology.hasHistory, resource[propertyHistory])) + except Exception: + pass + try: # add history + propertyDefinition = property['relatingPropertyDefinition']['ref'] + g.add((resource[propertyDefinition], RDF.type, ontology.PropertySet)) + g.add((resource[propertyID], ontology.relatedProperty, resource[propertyDefinition])) + except Exception: + pass + try: # add history + for obj in property['relatedObjects']: + propertyObject = obj['ref'] + g.add((resource[propertyObject], RDF.type, ontology.Object)) + g.add((resource[propertyID], ontology.relatedObject, resource[propertyObject])) + except Exception: + pass + return 1 + +def ifcWallTypeFunction(IfcWallType): + for walltype in IfcWallType: + wallID = walltype['globalId'] + #basic information + g.add((resource[wallID], RDF.type, ontology.WallType)) + try:#name is not always there + wallName = walltype['name'] + g.add((resource[wallID], ontology.name, Literal(wallName))) + except Exception: + pass + try:#predefinedType is not always there + wallPredefinedType = walltype['predefinedType'] + g.add((resource[wallID], ontology.predefinedType, Literal(wallPredefinedType))) + except Exception: + pass + try:#add history + wallOwnerHistory = walltype['ownerHistory']['ref'] + g.add((resource[ wallOwnerHistory], RDF.type, ontology.History)) + g.add((resource[wallID], ontology.hasHistory, resource[ wallOwnerHistory])) + except Exception: + pass + try:#tag is not always there + wallTag = walltype['tag'] + g.add((resource[wallID], ontology.tag, Literal(wallTag))) + except Exception: + pass + try:#material is not always there + for material in walltype['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[wallID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in walltype['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[wallID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try: # material is not always there + for typed in walltype['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[wallID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#representationMaps data + for maps in walltype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[wallID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], RDF.type, ontology.Representation)) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xlocation, Literal(maps['mappingOrigin']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ylocation, Literal(maps['mappingOrigin']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zlocation, Literal(maps['mappingOrigin']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.yaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ydirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcWindowTypeFunction(IfcWindowType): + for windowtype in IfcWindowType: + windowID = windowtype['globalId'] + #basic information + g.add((resource[windowID], RDF.type, ontology.WindowType)) + try:#name is not always there + windowName = windowtype['name'] + g.add((resource[windowID], ontology.name, Literal(windowName))) + except Exception: + pass + try:#predefinedType is not always there + windowPredefinedType = windowtype['predefinedType'] + g.add((resource[windowID], ontology.predefinedType, Literal(windowPredefinedType))) + except Exception: + pass + try:#partitioningType is not always there + windowPartitioningType = windowtype['partitioningType'] + g.add((resource[windowID], ontology.partitioningType, Literal(windowPartitioningType))) + except Exception: + pass + try:#add history + windowOwnerHistory = windowtype['ownerHistory']['ref'] + g.add((resource[ windowOwnerHistory], RDF.type, ontology.History)) + g.add((resource[windowID], ontology.hasHistory, resource[ windowOwnerHistory])) + except Exception: + pass + try:#add history + windowTag = windowtype['tag'] + g.add((resource[windowID], ontology.tag, Literal(windowTag))) + except Exception: + pass + try:#material is not always there + for material in windowtype['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[windowID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#object is not always there + count = 1 + for prp in windowtype['hasPropertySets']: + isprp = prp['ref'] + g.add((resource["propertyset_" + isprp + "_" + str(count)], RDF.type, ontology.PropertySet)) + g.add((resource[windowID], ontology.hasProperty, resource["propertyset_" + isprp + "_" + str(count)])) + count += 1 + except Exception: + pass + try: # material is not always there + for typed in windowtype['types']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[windowID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#representationMaps data + for maps in windowtype['representationMaps']: + #print(maps['mappingOrigin']) + g.add((resource[windowID], ontology.hasRepresentationType, resource[ maps['mappedRepresentation']['ref']])) + g.add((resource[ maps['mappedRepresentation']['ref']], RDF.type, ontology.Representation)) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xlocation, Literal(maps['mappingOrigin']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ylocation, Literal(maps['mappingOrigin']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zlocation, Literal(maps['mappingOrigin']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.yaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zaxis, + Literal(maps['mappingOrigin']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.xdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.ydirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource[ maps['mappedRepresentation']['ref']], ontology.zdirection, + Literal(maps['mappingOrigin']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcWallFunction(IfcWall): + for wall in IfcWall: + wallID = wall['globalId'] + #basic information + g.add((resource[wallID], RDF.type, ontology.Wall)) + try:#predefinedType is not always there + wallPredefinedType = wall['predefinedType'] + g.add((resource[wallID], ontology.predefinedType, Literal(wallPredefinedType))) + except Exception: + pass + try:#tag is not always there + wallTag = wall['tag'] + g.add((resource[wallID], ontology.tag, Literal(wallTag))) + except Exception: + pass + try:#tag is not always there + wallName = wall['name'] + g.add((resource[wallID], ontology.name, Literal(wallName))) + except Exception: + pass + try:#tag is not always there + wallObjectType = wall['objectType'] + g.add((resource[wallID], ontology.type, Literal(wallObjectType))) + except Exception: + pass + try:#add history + wallHistory = wall['ownerHistory']['ref'] + g.add((resource[wallHistory], RDF.type, ontology.History)) + g.add((resource[wallID], ontology.hasHistory, resource[wallHistory])) + except Exception: + pass + try:#material is not always there + for material in wall['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[wallID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#isTypedBy is not always there + for typed in wall['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[wallID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in wall['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[wallID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try:#definedby is not always there + for defined in wall['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[wallID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#representation is not always there + for representation in wall['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[wallID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#structure is not always there + for structure in wall['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[wallID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#opening is not always there + for void in wall['hasOpenings']: + opening = void['ref'] + g.add((resource[opening], RDF.type, ontology.Opening)) + g.add((resource[wallID], ontology.hasOpening, resource[opening])) + except Exception: + pass + try:#representationMaps data + g.add((resource[wallID], ontology.hasPlacement, resource["plamenent_" + wallID + "_1"])) + g.add((resource["plamenent_" + wallID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + wallID + "_1"], ontology.xlocation, Literal(wall['objectPlacement']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.ylocation, Literal(wall['objectPlacement']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.zlocation, Literal(wall['objectPlacement']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.xaxis, + Literal(wall['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.yaxis, + Literal(wall['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.zaxis, + Literal(wall['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.xdirection, + Literal(wall['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.ydirection, + Literal(wall['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_1"], ontology.zdirection, + Literal(wall['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[wallID], ontology.hasPlacement, resource["plamenent_" + wallID + "_2"])) + g.add((resource["plamenent_" + wallID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + wallID + "_2"], ontology.xlocation, Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.ylocation, Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.zlocation, Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.xaxis, + Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.yaxis, + Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.zaxis, + Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.xdirection, + Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.ydirection, + Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_2"], ontology.zdirection, + Literal(wall['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[wallID], ontology.hasPlacement, resource["plamenent_" + wallID + "_3"])) + g.add((resource["plamenent_" + wallID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + wallID + "_3"], ontology.xlocation, Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.ylocation, Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.zlocation, Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.xaxis, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.yaxis, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.zaxis, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.xdirection, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.ydirection, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_3"], ontology.zdirection, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[wallID], ontology.hasPlacement, resource["plamenent_" + wallID + "_4"])) + g.add((resource["plamenent_" + wallID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + wallID + "_4"], ontology.xlocation, Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.ylocation, Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.zlocation, Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.xaxis, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.yaxis, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.zaxis, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.xdirection, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.ydirection, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + wallID + "_4"], ontology.zdirection, + Literal(wall['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcWindowFunction(IfcWindow): + for window in IfcWindow: + windowID = window['globalId'] + #basic information + g.add((resource[windowID], RDF.type, ontology.Window)) + try:#name is not always there + windowName = window['name'] + g.add((resource[windowID], ontology.name, Literal(windowName))) + except Exception: + pass + try:#tag is not always there + windowTag = window['tag'] + g.add((resource[windowID], ontology.tag, Literal(windowTag))) + except Exception: + pass + try:#type is not always there + windowType = window['objectType'] + g.add((resource[windowID], ontology.type, Literal(windowType))) + except Exception: + pass + try:#predefinedType is not always there + windowPredefined = window['predefinedType'] + g.add((resource[windowID], ontology.predefinedType, Literal(windowPredefined))) + except Exception: + pass + try:#partitioningType is not always there + windowPartitiong = window['partitioningType'] + g.add((resource[windowID], ontology.partitioningType, Literal(windowPartitiong))) + except Exception: + pass + try:#add history + windowHistory = window['ownerHistory']['ref'] + g.add((resource[windowHistory], RDF.type, ontology.History)) + g.add((resource[windowID], ontology.hasHistory, resource[windowHistory])) + except Exception: + pass + try:#Height/Width is not always there + windowHeight, windowWidth = window['overallHeight'], window['overallWidth'] + g.add((resource[windowID], ontology.height, Literal(windowHeight))) + g.add((resource[windowID], ontology.width, Literal(windowWidth))) + except Exception: + pass + try:#isTypedBy is not always there + for typed in window['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[windowID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#material is not always there + for material in window['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[windowID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#fillsVoid is not always there + for void in window['fillsVoids']: + isvoid = void['ref'] + g.add((resource[isvoid], RDF.type, ontology.Void)) + g.add((resource[windowID], ontology.fillsVoid, resource[isvoid])) + except Exception: + pass + try:#structure is not always there + for structure in window['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[windowID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#definedby is not always there + for defined in window['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[windowID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#representation is not always there + for representation in window['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[windowID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in window['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[windowID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try:#representationMaps data + g.add((resource[windowID], ontology.hasPlacement, resource["plamenent_" + windowID + "_1"])) + g.add((resource["plamenent_" + windowID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + windowID + "_1"], ontology.xlocation, Literal(window['objectPlacement']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.ylocation, Literal(window['objectPlacement']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.zlocation, Literal(window['objectPlacement']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.xaxis, + Literal(window['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.yaxis, + Literal(window['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.zaxis, + Literal(window['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.xdirection, + Literal(window['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.ydirection, + Literal(window['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_1"], ontology.zdirection, + Literal(window['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[windowID], ontology.hasPlacement, resource["plamenent_" + windowID + "_2"])) + g.add((resource["plamenent_" + windowID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + windowID + "_2"], ontology.xlocation, Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.ylocation, Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.zlocation, Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.xaxis, + Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.yaxis, + Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.zaxis, + Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.xdirection, + Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.ydirection, + Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_2"], ontology.zdirection, + Literal(window['objectPlacement']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[windowID], ontology.hasPlacement, resource["plamenent_" + windowID + "_3"])) + g.add((resource["plamenent_" + windowID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + windowID + "_3"], ontology.xlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.ylocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.zlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.xaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.yaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.zaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.xdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.ydirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_3"], ontology.zdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[windowID], ontology.hasPlacement, resource["plamenent_" + windowID + "_4"])) + g.add((resource["plamenent_" + windowID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + windowID + "_4"], ontology.xlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.ylocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.zlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.xaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.yaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.zaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.xdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.ydirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_4"], ontology.zdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource[windowID], ontology.hasPlacement, resource["plamenent_" + windowID + "_5"])) + g.add((resource["plamenent_" + windowID + "_5"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + windowID + "_5"], ontology.xlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.ylocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.zlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.xaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.yaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.zaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.xdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.ydirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_5"], ontology.zdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try:#representationMaps data + g.add((resource[windowID], ontology.hasPlacement, resource["plamenent_" + windowID + "_6"])) + g.add((resource["plamenent_" + windowID + "_6"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + windowID + "_6"], ontology.xlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.ylocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.zlocation, Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.xaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.yaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.zaxis, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.xdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.ydirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + windowID + "_6"], ontology.zdirection, + Literal(window['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcGroupFunction(IfcGroup): + for group in IfcGroup: + groupID = group['globalId'] + # basic information + g.add((resource[groupID], RDF.type, ontology.Group)) + try: # predefinedType is not always there + groupPredefinedType = group['predefinedType'] + g.add((resource[groupID], ontology.predefinedType, Literal(groupPredefinedType))) + except Exception: + pass + try: # predefinedType is not always there + groupObjectType = group['objectType'] + g.add((resource[groupID], ontology.type, Literal(groupObjectType))) + except Exception: + pass + try: # name is not always there + groupName = group['name'] + g.add((resource[groupID], ontology.name, Literal(groupName))) + except Exception: + pass + try: # add history + groupHistory = group['ownerHistory']['ref'] + g.add((resource[groupHistory], RDF.type, ontology.History)) + g.add((resource[groupID], ontology.hasHistory, resource[groupHistory])) + except Exception: + pass + try: # structure is not always there + for grouped in group['isGroupedBy']: + isgrouped = grouped['ref'] + g.add((resource[isgrouped], RDF.type, ontology.Group)) + g.add((resource[groupID], ontology.isGroupedBy, resource[isgrouped])) + except Exception: + pass + return 1 + +def ifcRelAssignsToGroupFunction(IfcRelAssignsToGroup): + for propertySet in IfcRelAssignsToGroup: + propertySetID = propertySet['globalId'] + #basic information + g.add((resource[propertySetID], RDF.type, ontology.PropertySet)) + try:#add history + propertySetHistory = propertySet['ownerHistory']['ref'] + g.add((resource[propertySetHistory], RDF.type, ontology.History)) + g.add((resource[propertySetID], ontology.hasHistory, resource[propertySetHistory])) + except Exception: + pass + try: + for obj in propertySet['relatedObjects']: + propertyObject = obj['ref'] + g.add((resource[propertyObject], RDF.type, ontology.Object)) + g.add((resource[propertySetID], ontology.relatedObject, resource[propertyObject])) + except Exception: + pass + try: + propertyGroup = propertySet['relatingGroup']['ref'] + g.add((resource[propertyGroup], RDF.type, ontology.Group)) + g.add((resource[propertySetID], ontology.relatedGroup, resource[propertyGroup])) + except Exception: + pass + return 1 + +def ifcPropertySetFunction(IfcPropertySet): + for propertySet in IfcPropertySet: + propertySetID = propertySet['globalId'] + #basic information + g.add((resource[propertySetID], RDF.type, ontology.PropertySet)) + try:#add history + propertySetHistory = propertySet['ownerHistory']['ref'] + g.add((resource[propertySetHistory], RDF.type, ontology.History)) + g.add((resource[propertySetID], ontology.hasHistory, resource[propertySetHistory])) + except Exception: + pass + try:#name is not always there + propertySetIDName = propertySet['name'] + g.add((resource[propertySetID], ontology.name, Literal(propertySetIDName))) + except Exception: + pass + try:#name is not always there + propertySetIDDescription = propertySet['description'] + g.add((resource[propertySetID], ontology.description, Literal(propertySetIDDescription))) + except Exception: + pass + count = 1 + try: + for prp in propertySet['hasProperties']: + type, name, nominalType, nominalValue = prp['type'], prp['name'], prp['nominalValue']['type'], prp['nominalValue']['value'] + g.add((resource["propertysetNominal_" + propertySetID + "_" + str(count)], RDF.type, ontology.PropertyDetail)) + g.add((resource[propertySetID], ontology.hasProperty, resource["propertysetNominal_" + propertySetID + "_" + str(count)])) + g.add((resource["propertysetNominal_" + propertySetID + "_" + str(count)], ontology.type, Literal(type))) + g.add((resource["propertysetNominal_" + propertySetID + "_" + str(count)], ontology.name, Literal(name))) + g.add((resource["propertysetNominal_" + propertySetID + "_" + str(count)], ontology.nominalType, Literal(nominalType))) + g.add((resource["propertysetNominal_" + propertySetID + "_" + str(count)], ontology.nominalValue, Literal(nominalValue))) + count += 1 + except Exception: + pass + try: + count = 1 + for prp in propertySet['definesOccurrence']: + occurence = prp['ref'] + g.add((resource["occurence_" + propertySetID + "_" + str(count)], RDF.type, ontology.Occurence)) + g.add((resource[propertySetID], ontology.definesOccurence, resource["occurence_" + occurence + "_" + str(count)])) + count += 1 + except Exception: + pass + + return 1 + +def ifcDoorPanelPropertiesFunction(IfcDoorPanelProperties): + for door in IfcDoorPanelProperties: + doorID = door['globalId'] + #basic information + g.add((resource[doorID], RDF.type, ontology.DoorPanel)) + try:#add history + doorHistory = door['ownerHistory']['ref'] + g.add((resource[doorHistory], RDF.type, ontology.History)) + g.add((resource[doorID], ontology.hasHistory, resource[doorHistory])) + except Exception: + pass + try:#name is not always there + doorName = door['name'] + g.add((resource[doorID], ontology.name, Literal(doorName))) + except Exception: + pass + try:#definedby is not always there + for defined in door['definesType']: + issdefined = defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.Representation)) + g.add((resource[doorID], ontology.hasRepresentationType, resource[issdefined])) + except Exception: + pass + try:#panelDepth is not always there + depth = door['panelDepth'] + g.add((resource[doorID], ontology.panelDepth, Literal(depth))) + except Exception: + pass + try:#liningThickness is not always there + operation = door['panelOperation'] + g.add((resource[doorID], ontology.panelOperation, Literal(operation))) + except Exception: + pass + try:#panelWidth is not always there + width = door['panelWidth'] + g.add((resource[doorID], ontology.panelWidth, Literal(width))) + except Exception: + pass + try:#panelPosition is not always there + position = door['panelPosition'] + g.add((resource[doorID], ontology.panelPosition, Literal(position))) + except Exception: + pass + return 1 + +def ifcSlabFunction(IfcSlab): + for slab in IfcSlab: + slabID = slab['globalId'] + #basic information + g.add((resource[slabID], RDF.type, ontology.Slab)) + try:#add history + slabHistory = slab['ownerHistory']['ref'] + g.add((resource[slabHistory], RDF.type, ontology.History)) + g.add((resource[slabID], ontology.hasHistory, resource[slabHistory])) + except Exception: + pass + try:#tag is not always there + slabTag = slab['tag'] + g.add((resource[slabID], ontology.tag, Literal(slabTag))) + except Exception: + pass + try:#add history + slabPredefinedType = slab['predefinedType'] + g.add((resource[slabID], ontology.predefinedType, Literal(slabPredefinedType))) + except Exception: + pass + try:#add history + slabObjectType = slab['objectType'] + g.add((resource[slabID], ontology.type, Literal(slabObjectType))) + except Exception: + pass + try:#name is not always there + slabName = slab['name'] + g.add((resource[slabID], ontology.name, Literal(slabName))) + except Exception: + pass + + try:#representation is not always there + for representation in slab['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[slabID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#definedby is not always there + for defined in slab['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[slabID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#material is not always there + for material in slab['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[slabID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in slab['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[slabID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try:#structure is not always there + for structure in slab['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[slabID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#isTypedBy is not always there + for typed in slab['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[slabID], ontology.hasType, resource[istyped])) + except Exception: + pass + try: # representationMaps data + g.add((resource[slabID], ontology.hasPlacement, resource["plamenent_" + slabID + "_1"])) + g.add((resource["plamenent_" + slabID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + slabID + "_1"], ontology.xlocation, + Literal(slab['objectPlacement']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.ylocation, + Literal(slab['objectPlacement']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.zlocation, + Literal(slab['objectPlacement']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.xaxis, + Literal(slab['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.yaxis, + Literal(slab['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.zaxis, + Literal(slab['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.xdirection, + Literal(slab['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.ydirection, + Literal(slab['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_1"], ontology.zdirection, + Literal(slab['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], + datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[slabID], ontology.hasPlacement, resource["plamenent_" + slabID + "_2"])) + g.add((resource["plamenent_" + slabID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + slabID + "_2"], ontology.xlocation, Literal( + slab['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.ylocation, Literal( + slab['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.zlocation, Literal( + slab['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.xaxis, + Literal( + slab['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.yaxis, + Literal( + slab['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.zaxis, + Literal( + slab['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.xdirection, + Literal(slab['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.ydirection, + Literal(slab['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_2"], ontology.zdirection, + Literal(slab['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[slabID], ontology.hasPlacement, resource["plamenent_" + slabID + "_3"])) + g.add((resource["plamenent_" + slabID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + slabID + "_3"], ontology.xlocation, Literal( + slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.ylocation, Literal( + slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.zlocation, Literal( + slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.xaxis, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.yaxis, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.zaxis, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.xdirection, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.ydirection, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_3"], ontology.zdirection, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[slabID], ontology.hasPlacement, resource["plamenent_" + slabID + "_4"])) + g.add((resource["plamenent_" + slabID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + slabID + "_4"], ontology.xlocation, Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.ylocation, Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.zlocation, Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.xaxis, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.yaxis, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.zaxis, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.xdirection, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.ydirection, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + slabID + "_4"], ontology.zdirection, + Literal(slab['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcMemberFunction(IfcMember): + + for member in IfcMember: + memberID = member['globalId'] + #basic information + g.add((resource[memberID], RDF.type, ontology.Member)) + try:#add history + memberHistory = member['ownerHistory']['ref'] + g.add((resource[memberHistory], RDF.type, ontology.History)) + g.add((resource[memberID], ontology.hasHistory, resource[memberHistory])) + except Exception: + pass + try:#name is not always there + memberName = member['name'] + g.add((resource[memberID], ontology.name, Literal(memberName))) + except Exception: + pass + try:#objectType is not always there + memberObjectType = member['objectType'] + g.add((resource[memberID], ontology.Type, Literal(memberObjectType))) + except Exception: + pass + try:#description is not always there + memberDescription = member['description'] + g.add((resource[memberID], ontology.description, Literal(memberDescription))) + except Exception: + pass + try:#name is not always there + memberTag = member['tag'] + g.add((resource[memberID], ontology.tag, Literal(memberTag))) + except Exception: + pass + try:#isTypedBy is not always there + for typed in member['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[memberID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#representation is not always there + for representation in member['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[memberID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#structure is not always there + for structure in member['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[memberID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#definedby is not always there + for defined in member['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[memberID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#material is not always there + for material in member['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[memberID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + + try: # representationMaps data + g.add((resource[memberID], ontology.hasPlacement, resource["plamenent_" + memberID + "_1"])) + g.add((resource["plamenent_" + memberID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + memberID + "_1"], ontology.xlocation, + Literal(member['objectPlacement']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.ylocation, + Literal(member['objectPlacement']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.zlocation, + Literal(member['objectPlacement']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.xaxis, + Literal(member['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.yaxis, + Literal(member['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.zaxis, + Literal(member['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.xdirection, + Literal(member['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.ydirection, + Literal(member['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_1"], ontology.zdirection, + Literal(member['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], + datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[memberID], ontology.hasPlacement, resource["plamenent_" + memberID + "_2"])) + g.add((resource["plamenent_" + memberID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + memberID + "_2"], ontology.xlocation, Literal( + member['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.ylocation, Literal( + member['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.zlocation, Literal( + member['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.xaxis, + Literal( + member['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.yaxis, + Literal( + member['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.zaxis, + Literal( + member['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.xdirection, + Literal(member['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.ydirection, + Literal(member['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_2"], ontology.zdirection, + Literal(member['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[memberID], ontology.hasPlacement, resource["plamenent_" + memberID + "_3"])) + g.add((resource["plamenent_" + memberID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + memberID + "_3"], ontology.xlocation, Literal( + member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.ylocation, Literal( + member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.zlocation, Literal( + member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.xaxis, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.yaxis, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.zaxis, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.xdirection, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.ydirection, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_3"], ontology.zdirection, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[memberID], ontology.hasPlacement, resource["plamenent_" + memberID + "_4"])) + g.add((resource["plamenent_" + memberID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + memberID + "_4"], ontology.xlocation, Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.ylocation, Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.zlocation, Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.xaxis, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.yaxis, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.zaxis, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.xdirection, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.ydirection, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + memberID + "_4"], ontology.zdirection, + Literal(member['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def ifcElementQuantityFunction(IfcElementQuantity): + for quantity in IfcElementQuantity: + quantityID = quantity['globalId'] + #basic information + g.add((resource[quantityID], RDF.type, ontology.Object)) + try:#add history + quantityHistory = quantity['ownerHistory']['ref'] + g.add((resource[quantityHistory], RDF.type, ontology.History)) + g.add((resource[quantityID], ontology.hasHistory, resource[quantityHistory])) + except Exception: + pass + try:#name is not always there + quantityName = quantity['name'] + g.add((resource[quantityID], ontology.name, Literal(quantityName))) + except Exception: + pass + try:#methodOfMeasurement is not always there + quantitymethodOfMeasurement = quantity['methodOfMeasurement'] + g.add((resource[quantityID], ontology.methodMeasurement, Literal(quantitymethodOfMeasurement))) + except Exception: + pass + try: + count = 1 + for prp in quantity['definesOccurrence']: + occurence = prp['ref'] + g.add((resource["occurence_" + quantityID + "_" + str(count)], RDF.type, ontology.Occurence)) + g.add((resource[quantityID], ontology.definesOccurence, resource["occurence_" + occurence + "_" + str(count)])) + count += 1 + except Exception: + pass + try: + count = 1 + for prp in quantity['quantities']: + g.add((resource["quantity_" + quantityID + "_" + str(count)], RDF.type, ontology.Quantity)) + g.add((resource[quantityID], ontology.hasQuantity, resource["quantity_" + quantityID + "_" + str(count)])) + + for k in list(prp.keys()): + if k == "hasQuantities": + for l in prp[k]: + for second in list(l.keys()): + second_key = "secondQuantity_" + second + g.add((resource["quantity_" + quantityID + "_" + str(count)], ontology[second_key], Literal(l[second]))) + else: + g.add((resource["quantity_" + quantityID + "_" + str(count)], ontology[k], Literal(prp[k]))) + + count += 1 + except Exception: + pass + return 1 + +def ifcBeamFunction(IfcBeam): + for beam in IfcBeam: + beamID = beam['globalId'] + #basic information + g.add((resource[beamID], RDF.type, ontology.Beam)) + try:#add history + beamHistory = beam['ownerHistory']['ref'] + g.add((resource[beamHistory], RDF.type, ontology.History)) + g.add((resource[beamID], ontology.hasHistory, resource[beamHistory])) + except Exception: + pass + try:#add history + beamTag = beam['tag'] + g.add((resource[beamID], ontology.tag, Literal(beamTag))) + except Exception: + pass + try:#add history + beamObjectType = beam['objectType'] + g.add((resource[beamID], ontology.type, Literal(beamObjectType))) + except Exception: + pass + try:#add history + beamPredefinedType = beam['predefinedType'] + g.add((resource[beamID], ontology.predefinedType, Literal(beamPredefinedType))) + except Exception: + pass + try:#name is not always there + beamName = beam['name'] + g.add((resource[beamID], ontology.name, Literal(beamName))) + except Exception: + pass + try:#name is not always there + beamDescription = beam['description'] + g.add((resource[beamID], ontology.description, Literal(beamDescription))) + except Exception: + pass + try:#representation is not always there + for representation in beam['representation']['representations']: + rep = representation['ref'] + g.add((resource[rep], RDF.type, ontology.Representation)) + g.add((resource[beamID], ontology.hasRepresentationType, resource[rep])) + except Exception: + pass + try:#definedby is not always there + for defined in beam['isDefinedBy']: + issdefined= defined['ref'] + g.add((resource[issdefined], RDF.type, ontology.PropertySet)) + g.add((resource[beamID], ontology.isDefinedBy, resource[issdefined])) + except Exception: + pass + try:#material is not always there + for material in beam['hasAssociations']: + ismaterial = material['ref'] + g.add((resource[ismaterial], RDF.type, ontology.Material)) + g.add((resource[beamID], ontology.associatesMaterial, resource[ismaterial])) + except Exception: + pass + try:#structure is not always there + for structure in beam['containedInStructure']: + isstructure= structure['ref'] + g.add((resource[isstructure], RDF.type, ontology.Structure)) + g.add((resource[beamID], ontology.inStructure, resource[isstructure])) + except Exception: + pass + try:#isTypedBy is not always there + for typed in beam['isTypedBy']: + istyped = typed['ref'] + g.add((resource[istyped], RDF.type, ontology.TypeCategory)) + g.add((resource[beamID], ontology.hasType, resource[istyped])) + except Exception: + pass + try:#hasAssociations is not always there + for typed in beam['hasAssignments']: + iselement = typed['ref'] + g.add((resource[iselement], RDF.type, ontology.Group)) + g.add((resource[beamID], ontology.hasAssignments, resource[iselement])) + except Exception: + pass + try: # representationMaps data + g.add((resource[beamID], ontology.hasPlacement, resource["plamenent_" + beamID + "_1"])) + g.add((resource["plamenent_" + beamID + "_1"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + beamID + "_1"], ontology.xlocation, + Literal(beam['objectPlacement']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.ylocation, + Literal(beam['objectPlacement']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.zlocation, + Literal(beam['objectPlacement']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.xaxis, + Literal(beam['objectPlacement']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.yaxis, + Literal(beam['objectPlacement']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.zaxis, + Literal(beam['objectPlacement']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.xdirection, + Literal(beam['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.ydirection, + Literal(beam['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_1"], ontology.zdirection, + Literal(beam['objectPlacement']['relativePlacement']['refDirection']['directionRatios'][2], + datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[beamID], ontology.hasPlacement, resource["plamenent_" + beamID + "_2"])) + g.add((resource["plamenent_" + beamID + "_2"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + beamID + "_2"], ontology.xlocation, Literal( + beam['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.ylocation, Literal( + beam['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.zlocation, Literal( + beam['objectPlacement']['placementRelTo']['relativePlacement']['location']['coordinates'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.xaxis, + Literal( + beam['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.yaxis, + Literal( + beam['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.zaxis, + Literal( + beam['objectPlacement']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], + datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.xdirection, + Literal(beam['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.ydirection, + Literal(beam['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_2"], ontology.zdirection, + Literal(beam['objectPlacement']['placementRelTo']['relativePlacement']['refDirection'][ + 'directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[beamID], ontology.hasPlacement, resource["plamenent_" + beamID + "_3"])) + g.add((resource["plamenent_" + beamID + "_3"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + beamID + "_3"], ontology.xlocation, Literal( + beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.ylocation, Literal( + beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.zlocation, Literal( + beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['location'][ + 'coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.xaxis, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.yaxis, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.zaxis, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement']['axis'][ + 'directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.xdirection, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.ydirection, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_3"], ontology.zdirection, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['relativePlacement'][ + 'refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + try: + g.add((resource[beamID], ontology.hasPlacement, resource["plamenent_" + beamID + "_4"])) + g.add((resource["plamenent_" + beamID + "_4"], RDF.type, ontology.Placement)) + g.add((resource["plamenent_" + beamID + "_4"], ontology.xlocation, Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.ylocation, Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.zlocation, Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['location']['coordinates'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.xaxis, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.yaxis, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.zaxis, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['axis']['directionRatios'][2], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.xdirection, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][0], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.ydirection, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][1], datatype=XSD.decimal))) + g.add((resource["plamenent_" + beamID + "_4"], ontology.zdirection, + Literal(beam['objectPlacement']['placementRelTo']['placementRelTo']['placementRelTo']['relativePlacement']['refDirection']['directionRatios'][2], datatype=XSD.decimal))) + except Exception: + pass + return 1 + +def read_ttl_and_store_in_graphdb(ttl_file_path, graphdb_endpoint, graphdb_repository, username=None, password=None): + """ + Reads RDF data from a Turtle file and stores it in a GraphDB repository. + + :param ttl_file_path: Path to the Turtle file. + :param graphdb_endpoint: URL of the GraphDB endpoint. + :param graphdb_repository: Name of the GraphDB repository. + :param username: (Optional) Username for GraphDB authentication. + :param password: (Optional) Password for GraphDB authentication. + """ + # Create a graph + graph = Graph() + + # Parse the Turtle file + graph.parse(ttl_file_path, format="turtle") + + # Serialize the graph to a string in N-Triples format + ntriples_data = graph.serialize(format='nt') + + # If ntriples_data is bytes, decode it to string + if isinstance(ntriples_data, bytes): + ntriples_data = ntriples_data.decode('utf-8') + + # Create a SPARQLWrapper instance for the GraphDB endpoint + sparql = SPARQLWrapper(f"{graphdb_endpoint}/repositories/{graphdb_repository}/statements") + sparql.setMethod(POST) + sparql.setRequestMethod(URLENCODED) + sparql.addParameter('update', f""" + INSERT DATA {{ + {ntriples_data} + }} + """) + + # Set credentials if provided + if username and password: + sparql.setHTTPAuth(BASIC) + sparql.setCredentials(username, password) + + # Send the request to the GraphDB repository + sparql.query() + + +def receive_json(ifcJson): + # Your main logic using the JSON data + print("Received JSON:", type(ifcJson)) + + IfcBuildingStorey, IfcRelDefinesByType, IfcBeamType, IfcRelFillsElement, IfcDoor, IfcOwnerHistory, ifcSlabType, IfcRelContainedInSpatialStructure, IfcRelAssociatesMaterial, \ + IfcBuilding, IfcColumnType, IfcColumn, IfcMemberType, IfcSite, IfcOpeningElement, IfcRelAggregates, IfcGeometricRepresentationContext, IfcWindowLiningProperties,\ + IfcRelVoidsElement, IfcDoorType, IfcGeometricRepresentationSubContext, IfcDoorLiningProperties, IfcRelDefinesByProperties, IfcWallType, IfcWindowType, IfcWall, \ + IfcWindow, IfcGroup, IfcRelAssignsToGroup, IfcProject, IfcPropertySet, IfcSlab, IfcDoorPanelProperties, IfcMember, IfcElementQuantity, IfcBeam, IfcShapeRepresentation = parser(ifcJson) + + ifcRelDefinesByTypeFunction(IfcRelDefinesByType) + ifcBuildingStoreyFunction(IfcBuildingStorey) + ifcBeamTypeFunction(IfcBeamType) + ifcRelFillsElementFunction(IfcRelFillsElement) + ifcDoorFunction(IfcDoor) + ifcOwnerHistoryFunction(IfcOwnerHistory) + ifcSlabTypeFunction(ifcSlabType) + ifcRelContainedInSpatialStructureFunction(IfcRelContainedInSpatialStructure) + ifcRelAssociatesMaterialFunction(IfcRelAssociatesMaterial) + ifcBuilingFunction(IfcBuilding) + ifcColumnTypeFunction(IfcColumnType) + ifcColumnFunction(IfcColumn) + ifcMemberTypeFunction(IfcMemberType) + ifcSiteFunction(IfcSite) + ifcOpeningElementFunction(IfcOpeningElement) + ifcRelAggregatesFunction(IfcRelAggregates) + ifcGeometricRepresentationContextFunction(IfcGeometricRepresentationContext) + ifcWindowLiningPropertiesFunction(IfcWindowLiningProperties) + ifcRelVoidsElementFunction(IfcRelVoidsElement) + ifcDoorTypeFunction(IfcDoorType) + ifcDoorLiningPropertiesFunction(IfcDoorLiningProperties) + ifcRelDefinesByPropertiesFunction(IfcRelDefinesByProperties) + ifcWallTypeFunction(IfcWallType) + ifcWindowTypeFunction(IfcWindowType) + ifcWallFunction(IfcWall) + ifcWindowFunction(IfcWindow) + ifcGroupFunction(IfcGroup) + ifcRelAssignsToGroupFunction(IfcRelAssignsToGroup) + ifcPropertySetFunction(IfcPropertySet) + ifcSlabFunction(IfcSlab) + ifcDoorPanelPropertiesFunction(IfcDoorPanelProperties) + ifcMemberFunction(IfcMember) + ifcElementQuantityFunction(IfcElementQuantity) + ifcBeamFunction(IfcBeam) + + + #Class for IfcProject + projectClass = project(IfcProject, g, ontology, resource) + projectClass.ifcProjectFunction() + + #Class for ifcGeometricRepresentationSubContextFunction + geometricClass = geometric(IfcGeometricRepresentationSubContext, g, ontology, resource) + geometricClass.ifcGeometricRepresentationSubContextFunction() + + #Class for ifcShapeRepresentation + shapeClass = shape(IfcShapeRepresentation, g, ontology, resource) + shapeClass.ifcShapeRepresentationFunction() + + # Create RDF triples + # Serialize and save the RDF graph to a TTL file + file_path = "output.ttl" + g.serialize(destination=file_path, format="turtle") + + print(f"RDF triples dumped to '{file_path}' successfully.") + ttl_file_path = 'output.ttl' # Replace with the path to your Turtle file + graphdb_endpoint = 'http://localhost:7200' # Replace with the URL of your GraphDB endpoint + graphdb_repository = 'model_madrid' # Replace with the name of your GraphDB repository + username = 'admin' # Replace with your GraphDB username (if required) + password = 'root' # Replace with your GraphDB password (if required) + #test pc certh, this is new + # read_ttl_and_store_in_graphdb(ttl_file_path, graphdb_endpoint, graphdb_repository, username, password) + print("Data was mapped in GraphDB") + return 1 \ No newline at end of file diff --git a/ifcParser/ifcProject.py b/ifcParser/ifcProject.py new file mode 100644 index 0000000..501e1ee --- /dev/null +++ b/ifcParser/ifcProject.py @@ -0,0 +1,146 @@ +from rdflib import Graph, Namespace, URIRef, Literal, RDF, RDFS, XSD + + +class project(): + + def __init__(self, IfcProject, g, ontology, resource): + self.IfcProject = IfcProject + self.g = g + self.ontology = ontology + self.resource = resource + + def ifcProjectFunction(self): + for proj in self.IfcProject: + projectID = proj['globalId'] + #basic information + self.g.add((self.resource[projectID], RDF.type, self.ontology.Project)) + try:#add history + projectHistory = proj['ownerHistory']['ref'] + self.g.add((self.resource[projectHistory], RDF.type, self.ontology.History)) + self.g.add((self.resource[projectID], self.ontology.hasHistory, self.resource[projectHistory])) + except Exception: + pass + try: # name is not always there + projName = proj['name'] + self.g.add((self.resource[projectID], self.ontology.name, Literal(projName))) + except Exception: + pass + try: # description is not always there + projDescription = proj['description'] + self.g.add((self.resource[projectID], self.ontology.description, Literal(projDescription))) + except Exception: + pass + try: # description is not always there + projLongName = proj['longName'] + self.g.add((self.resource[projectID], self.ontology.longName, Literal(projLongName))) + except Exception: + pass + try: # description is not always there + projPhase = proj['phase'] + self.g.add((self.resource[projectID], self.ontology.phase, Literal(projPhase))) + except Exception: + pass + try: # representationContexts is not always there + for representationContexts in proj['representationContexts']: + context = representationContexts['ref'] + self.g.add((self.resource[context], RDF.type, self.ontology.Context)) + self.g.add((self.resource[projectID], self.ontology.hasRepresentationContext, self.resource[context])) + except Exception: + pass + try: # definedby is not always there + for defined in proj['isDefinedBy']: + issdefined = defined['ref'] + self.g.add((self.resource[issdefined], RDF.type, self.ontology.PropertySet)) + self.g.add((self.resource[projectID], self.ontology.isDefinedBy, self.resource[issdefined])) + except Exception: + pass + try: # decompose is not always there + for representation in proj['isDecomposedBy']: + rep = representation['ref'] + self.g.add((self.resource["building_" + projectID], RDF.type, self.ontology.Object)) + self.g.add((self.resource[rep], self.ontology.isDecomposedBy, self.resource["building_" + projectID])) + except Exception: + pass + try: # decompose is not always there + for representation in proj['declares']: + rep = representation['ref'] + self.g.add((self.resource["declaration_" + projectID], RDF.type, self.ontology.RelationDeclaration)) + self.g.add((self.resource[rep], self.ontology.declares, self.resource["declaration_" + projectID])) + except Exception: + pass + try: + count, countElement = 1, 1 + for unit in proj['unitsInContext']['units']: + unitType = unit['type'] + print(unitType) + if unitType == "IfcSIUnit": + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], RDF.type, self.ontology.IfcSIUnit)) + self.g.add((self.resource[projectID], self.ontology.hasUnit, self.resource["ifcUnit_" + projectID + "_" + str(count)])) + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.unitType, Literal(unit['unitType']))) + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.name, Literal(unit['name']))) + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.dimensionType, Literal(unit['dimensions']['type']))) + if 'prefix' in list(unit.keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.prefix, Literal(unit['prefix']))) + if 'LengthExponent' in list(unit['dimensions'].keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.LengthExponent, Literal(unit['dimensions']['LengthExponent']))) + if 'TimeExponent' in list(unit['dimensions'].keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.TimeExponent, Literal(unit['dimensions']['TimeExponent']))) + if 'ThermodynamicTemperatureExponent' in list(unit['dimensions'].keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.ThermodynamicTemperatureExponent, Literal(unit['dimensions']['ThermodynamicTemperatureExponent']))) + if 'MassExponent' in list(unit['dimensions'].keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.MassExponent, Literal(unit['dimensions']['MassExponent']))) + if 'ElectricCurrentExponent' in list(unit['dimensions'].keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.ElectricCurrentExponent, Literal(unit['dimensions']['ElectricCurrentExponent']))) + if 'LuminousIntensityExponent' in list(unit['dimensions'].keys()): + self.g.add((self.resource["ifcUnit_" + projectID + "_" + str(count)], self.ontology.LuminousIntensityExponent, Literal(unit['dimensions']['LuminousIntensityExponent']))) + elif unitType == "IfcConversionBasedUnit": + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], RDF.type, self.ontology.ConversionBasedUnit)) + self.g.add((self.resource[projectID], self.ontology.hasUnit, self.resource["conversionBasedUnit_" + projectID + "_" + str(count)])) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.unitType, Literal(unit['unitType']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.name, Literal(unit['name']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.coversionType, Literal(unit['conversionFactor']['valueComponent']['type']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.coversionValue, Literal(unit['conversionFactor']['valueComponent']['value']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.componentType, Literal(unit['conversionFactor']['unitComponent']['unitType']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.componentName, Literal(unit['conversionFactor']['unitComponent']['name']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.dimensionType, Literal(unit['conversionFactor']['unitComponent']['dimensions']['type']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.LengthExponent, Literal(unit['dimensions']['lengthExponent']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.MassExponent, Literal(unit['dimensions']['massExponent']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.TimeExponent, Literal(unit['dimensions']['timeExponent']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.ElectricCurrentExponent, Literal(unit['dimensions']['electricCurrentExponent']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.ThermodynamicTemperatureExponent, Literal(unit['dimensions']['thermodynamicTemperatureExponent']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.AmountOfSubstanceExponent, Literal(unit['dimensions']['amountOfSubstanceExponent']))) + self.g.add((self.resource["conversionBasedUnit_" + projectID + "_" + str(count)], self.ontology.LuminousIntensityExponent, Literal(unit['dimensions']['luminousIntensityExponent']))) + elif unitType == "IfcDerivedUnit": + self.g.add((self.resource["derivedUnit_" + projectID + "_" + str(count)], RDF.type, self.ontology.DerivedUnit)) + self.g.add((self.resource[projectID], self.ontology.hasUnit, self.resource["derivedUnit_" + projectID + "_" + str(count)])) + self.g.add((self.resource["derivedUnit_" + projectID + "_" + str(count)], self.ontology.unitType, Literal(unit['unitType']))) + for element in unit['elements']: + + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], RDF.type, self.ontology.DerivedUnit)) + self.g.add((self.resource["derivedUnit_" + projectID + "_" + str(count)], self.ontology.hasElement, self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)])) + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], self.ontology.type, Literal(element['unit']['unitType']))) + try: + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], + self.ontology.prefix, Literal(element['prefix']))) + except Exception: + pass + try: + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], self.ontology.name, Literal(element['unit']['name']))) + except Exception: + pass + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], self.ontology.exponent, Literal(element['exponent']))) + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], self.ontology.dimensionType, Literal(element['unit']['dimensions']['type']))) + for k in list(element['unit']['dimensions'].keys()): + if str(k) != "type": + self.g.add((self.resource["derivedUnitElement_" + projectID + "_" + str(countElement)], self.ontology[k], Literal(element['unit']['dimensions'][k]))) + countElement += 1 + else: + pass + count += 1 + except Exception: + pass + + # Create RDF triples + # Serialize and save the RDF graph to a TTL file + file_path = "output.ttl" + self.g.serialize(destination=file_path, format="turtle") \ No newline at end of file diff --git a/ifcParser/ifcShape.py b/ifcParser/ifcShape.py new file mode 100644 index 0000000..2036784 --- /dev/null +++ b/ifcParser/ifcShape.py @@ -0,0 +1,327 @@ +from rdflib import Graph, Namespace, URIRef, Literal, RDF, RDFS, XSD + + +class shape(): + + def __init__(self, IfcShapeRepresentation, g, ontology, resource): + self.IfcShapeRepresentation = IfcShapeRepresentation + self.g = g + self.ontology = ontology + self.resource = resource + + def ifcShapeRepresentationFunction(self): + for shape in self.IfcShapeRepresentation: + shapeID = shape['globalId'] + # basic information + self.g.add((self.resource[shapeID], RDF.type, self.ontology.Shape)) + try: # name is not always there + shapeIdentifier = shape['representationIdentifier'] + self.g.add((self.resource[shapeID], self.ontology.identifier, Literal(shapeIdentifier))) + except Exception: + pass + try: # description is not always there + shapeType = shape['representationType'] + self.g.add((self.resource[shapeID], self.ontology.type, Literal(shapeType))) + except Exception: + pass + try: + iscontext = shape['contextOfItems']['ref'] + self.g.add((self.resource[iscontext], RDF.type, self.ontology.Context)) + self.g.add((self.resource[shapeID], self.ontology.hasContext, self.resource[iscontext])) + except Exception: + pass + try: # material is not always there + count = 1 + for layer in shape['layerAssignments']: + layerType = layer['type'] + layerName = layer['name'] + self.g.add((self.resource["layer_" + shapeID + "_" + str(count)], RDF.type, self.ontology.Layer)) + self.g.add((self.resource[shapeID], self.ontology.hasLayer, self.resource["layer_" + shapeID + "_" + str(count)])) + self.g.add((self.resource["layer_" + shapeID + "_" + str(count)], self.ontology.name, Literal(layerName))) + self.g.add((self.resource["layer_" + shapeID + "_" + str(count)], self.ontology.type, Literal(layerType))) + for item in layer['assignedItems']: + itemID = item['ref'] + self.g.add( + (self.resource[itemID], RDF.type, self.ontology.Shape)) + self.g.add((self.resource["layer_" + shapeID + "_" + str(count)], self.ontology.hasShape, + self.resource[itemID])) + count += 1 + except Exception: + pass + try: # material is not always there + for representationMap in shape['representationMap']: + repID = representationMap['mappedRepresentation']['ref'] + self.g.add((self.resource["mapped_representation_" + repID], RDF.type, self.ontology.MappedRepresentation)) + self.g.add((self.resource[shapeID], self.ontology.hasMappedRepresentation, self.resource["mapped_representation_" + repID])) + self.g.add((self.resource["mapped_representation_" + repID], self.ontology.xlocation, + Literal(representationMap['mappingOrigin']['location'][ + 'coordinates'][0]))) + self.g.add((self.resource["mapped_representation_" + repID], self.ontology.ylocation, + Literal(representationMap['mappingOrigin']['location'][ + 'coordinates'][1]))) + self.g.add((self.resource["mapped_representation_" + repID], self.ontology.zlocation, + Literal(representationMap['mappingOrigin']['location'][ + 'coordinates'][2]))) + except Exception: + pass + try: # material is not always there + for representationType in shape['ofProductRepresentation']: + for rep in representationType['representations']: + repID = rep['ref'] + self.g.add((self.resource["representation_" + repID], RDF.type, self.ontology.Representation)) + self.g.add((self.resource[shapeID], self.ontology.hasRepresentation, self.resource["representation_" + repID])) + except Exception: + pass + try: # material is not always there + for shapeAspect in shape['ofShapeAspect']: + self.g.add((self.resource[shapeID], self.ontology.name, + Literal(shapeAspect["name"]))) + self.g.add((self.resource[shapeID], self.ontology.definition, + Literal(shapeAspect["productDefinitional"]))) + for rep in shapeAspect['shapeRepresentations']: + repID = rep['ref'] + self.g.add((self.resource["shape_representation_" + repID], RDF.type, self.ontology.ShapeRepresentation)) + self.g.add((self.resource[shapeID], self.ontology.hasShapeRepresentation, self.resource["shape_representation_" + repID])) + if 'representations' in list(shapeAspect['partOfProductDefinitionShape'].keys()): + for rep in shapeAspect['partOfProductDefinitionShape']['representations']: + repID = rep['ref'] + self.g.add((self.resource["mapped_representation_" + repID], RDF.type, self.ontology.MappedRepresentation)) + self.g.add((self.resource[shapeID], self.ontology.hasMappedRepresentation, self.resource["mapped_representation_" + repID])) + elif 'mappingOrigin' in list(shapeAspect['partOfProductDefinitionShape'].keys()): + self.g.add((self.resource["mapped_representation_" + shapeAspect['partOfProductDefinitionShape']['mappedRepresentation']['ref']], RDF.type, + self.ontology.MappedRepresentation)) + self.g.add((self.resource[shapeID], self.ontology.hasMappedRepresentation, + self.resource["mapped_representation_" + shapeAspect['partOfProductDefinitionShape']['mappedRepresentation']['ref']])) + self.g.add((self.resource["mapped_representation_" + shapeAspect['partOfProductDefinitionShape']['mappedRepresentation']['ref']], self.ontology.hasxlocation, + Literal(shapeAspect['partOfProductDefinitionShape']['mappingOrigin']['location']['coordinates'][0]))) + self.g.add((self.resource["mapped_representation_" + shapeAspect['partOfProductDefinitionShape']['mappedRepresentation']['ref']], self.ontology.hasylocation, + Literal(shapeAspect['partOfProductDefinitionShape']['mappingOrigin']['location']['coordinates'][1]))) + self.g.add((self.resource["mapped_representation_" + shapeAspect['partOfProductDefinitionShape']['mappedRepresentation']['ref']], self.ontology.haszlocation, + Literal(shapeAspect['partOfProductDefinitionShape']['mappingOrigin']['location']['coordinates'][2]))) + except Exception: + pass + try: # material is not always there + countpolygonalFace, countPolygonalCoord = 1, 1 + for item in shape['items']: + if item['type'] == "IfcExtrudedAreaSolid": + if 'depth' in list(item.keys()): + depth = item['depth'] + self.g.add((self.resource[shapeID], self.ontology.depth, Literal(depth))) + if 'extrudedDirection' in list(item.keys()): + self.g.add((self.resource[shapeID], self.ontology.xextrudedDirection, Literal(item['extrudedDirection']['directionRatios'][0]))) + self.g.add((self.resource[shapeID], self.ontology.yextrudedDirection, Literal(item['extrudedDirection']['directionRatios'][1]))) + self.g.add((self.resource[shapeID], self.ontology.zextrudedDirection, Literal(item['extrudedDirection']['directionRatios'][2]))) + if 'position' in list(item.keys()): + if 'location' in list(item['position'].keys()): + self.g.add((self.resource[shapeID], self.ontology.xlocation, Literal(item['position']['location']['coordinates'][0]))) + self.g.add((self.resource[shapeID], self.ontology.ylocation, Literal(item['position']['location']['coordinates'][1]))) + self.g.add((self.resource[shapeID], self.ontology.zlocation, Literal(item['position']['location']['coordinates'][2]))) + if 'position' in list(item.keys()): + if 'axis' in list(item['position'].keys()): + self.g.add((self.resource[shapeID], self.ontology.xaxis, Literal(item['position']['axis']['directionRatios'][0]))) + self.g.add((self.resource[shapeID], self.ontology.yaxis, Literal(item['position']['axis']['directionRatios'][1]))) + self.g.add((self.resource[shapeID], self.ontology.zaxis, Literal(item['position']['axis']['directionRatios'][2]))) + if 'position' in list(item.keys()): + if 'refDirection' in list(item['position'].keys()): + self.g.add((self.resource[shapeID], self.ontology.xrefDirection, Literal(item['position']['refDirection']['directionRatios'][0]))) + self.g.add((self.resource[shapeID], self.ontology.yrefDirection, Literal(item['position']['refDirection']['directionRatios'][1]))) + self.g.add((self.resource[shapeID], self.ontology.zrefDirection, Literal(item['position']['refDirection']['directionRatios'][2]))) + if 'profileType' in list(item['sweptArea'].keys()): + self.g.add((self.resource[shapeID], self.ontology.sweptAreaType, Literal(item['sweptArea']['profileType']))) + if 'profileName' in list(item['sweptArea'].keys()): + self.g.add((self.resource[shapeID], self.ontology.sweptAreaName, Literal(item['sweptArea']['profileName']))) + if 'sweptArea' in list(item.keys()): + count = 1 + for coord in item['sweptArea']['outerCurve']['points']['coordList']: + self.g.add( + (self.resource["coord_" + shapeID + "_" + str(count)], RDF.type, self.ontology.Coord)) + self.g.add((self.resource[shapeID], self.ontology.hasCoord, + self.resource["coord_" + shapeID + "_" + str(count)])) + for constant in coord: + self.g.add( + (self.resource["coord_" + shapeID + "_" + str(count)], self.ontology.coord, + Literal(constant))) + count += 1 + countInner = 1 + if "innerCurves" in list(item['sweptArea'].keys()): + for inner in item['sweptArea']['innerCurves']: + for coord in inner['points']['coordList']: + self.g.add( + (self.resource["coordInner_" + shapeID + "_" + str(countInner)], RDF.type, + self.ontology.InnerCoord)) + self.g.add((self.resource[shapeID], self.ontology.hasInnerCoord, + self.resource["coordInner_" + shapeID + "_" + str(countInner)])) + + for constant in coord: + self.g.add( + (self.resource["coordInner_" + shapeID + "_" + str(countInner)], self.ontology.innercoord, + Literal(constant))) + countInner += 1 + if item['type'] == "IfcMappedItem": + if "mappingTarget" in list(item.keys()): + if len(item['mappingTarget']['localOrigin']['coordinates']) == 3: + self.g.add((self.resource[shapeID], self.ontology.xlocation, Literal(item['mappingTarget']['localOrigin']['coordinates'][0]))) + self.g.add((self.resource[shapeID], self.ontology.ylocation, Literal(item['mappingTarget']['localOrigin']['coordinates'][1]))) + self.g.add((self.resource[shapeID], self.ontology.zlocation, Literal(item['mappingTarget']['localOrigin']['coordinates'][2]))) + elif len(item['mappingTarget']['localOrigin']['coordinates']) == 2: + self.g.add((self.resource[shapeID], self.ontology.xlocation, Literal(item['mappingTarget']['localOrigin']['coordinates'][0]))) + self.g.add((self.resource[shapeID], self.ontology.ylocation, Literal(item['mappingTarget']['localOrigin']['coordinates'][1]))) + elif len(item['mappingTarget']['localOrigin']['coordinates']) == 1: + self.g.add((self.resource[shapeID], self.ontology.xlocation, Literal(item['mappingTarget']['localOrigin']['coordinates'][0]))) + else: + pass + if "scale" in list(item['mappingTarget'].keys()): + self.g.add((self.resource[shapeID], self.ontology.scale, + Literal(item['mappingTarget']['scale']))) + if "mappingSource" in list(item.keys()): + if len(item['mappingSource']['mappingOrigin']['location']['coordinates']) == 3: + self.g.add((self.resource[shapeID], self.ontology.location2X, Literal(item['mappingSource']['mappingOrigin']['location']['coordinates'][0]))) + self.g.add((self.resource[shapeID], self.ontology.location2Y, Literal(item['mappingSource']['mappingOrigin']['location']['coordinates'][1]))) + self.g.add((self.resource[shapeID], self.ontology.location2Z, Literal(item['mappingSource']['mappingOrigin']['location']['coordinates'][2]))) + elif len(item['mappingSource']['mappingOrigin']['location']['coordinates']) == 2: + self.g.add((self.resource[shapeID], self.ontology.location2X, Literal(item['mappingSource']['mappingOrigin']['location']['coordinates'][0]))) + self.g.add((self.resource[shapeID], self.ontology.location2Y, Literal(item['mappingSource']['mappingOrigin']['location']['coordinates'][1]))) + elif len(item['mappingSource']['mappingOrigin']['location']['coordinates']) == 1: + self.g.add((self.resource[shapeID], self.ontology.location2X, Literal(item['mappingSource']['mappingOrigin']['location']['coordinates'][0]))) + else: + pass + if item['type'] == "IfcIndexedPolyCurve": + if "points" in list(item.keys()): + self.g.add( + (self.resource["placement_" + shapeID], RDF.type, self.ontology.Placement)) + self.g.add((self.resource[shapeID], self.ontology.hasPlacement, + self.resource["placement_" + shapeID])) + count = 1 + for coord in item['points']['coordList']: + self.g.add( + (self.resource["coord_" + shapeID + "_" + str(count)], RDF.type, self.ontology.Coord)) + self.g.add((self.resource["placement_" + shapeID], self.ontology.hasCoord, + self.resource["coord_" + shapeID + "_" + str(count)])) + for constant in coord: + self.g.add( + (self.resource["coord_" + shapeID + "_" + str(count)], self.ontology.coord, + Literal(constant))) + count += 1 + if item['type'] == "IfcPolygonalFaceSet": + if "coordinates" in list(item.keys()): + self.g.add( + (self.resource["placement_" + shapeID], RDF.type, self.ontology.Placement)) + self.g.add((self.resource[shapeID], self.ontology.hasPlacement, + self.resource["placement_" + shapeID])) + + for coord in item['coordinates']['coordList']: + self.g.add( + (self.resource["coord_" + shapeID + "_" + str(countPolygonalCoord)], RDF.type, + self.ontology.Coord)) + self.g.add((self.resource["placement_" + shapeID], self.ontology.hasCoord, + self.resource["coord_" + shapeID + "_" + str(countPolygonalCoord)])) + for constant in coord: + self.g.add( + (self.resource["coord_" + shapeID + "_" + str(countPolygonalCoord)], self.ontology.coord, + Literal(constant))) + countPolygonalCoord += 1 + if "closed" in list(item.keys()): + self.g.add( + (self.resource[shapeID], self.ontology.closed, + Literal(item['closed']))) + if "faces" in list(item.keys()): + self.g.add( + (self.resource["placementFacet_" + shapeID], RDF.type, self.ontology.Placement)) + self.g.add((self.resource[shapeID], self.ontology.hasFacetPlacement, + self.resource["placementFacet_" + shapeID])) + for face in item['faces']: + self.g.add( + (self.resource["faces_" + shapeID + "_" + str(countpolygonalFace)], RDF.type, + self.ontology.Face)) + self.g.add((self.resource["placementFacet_" + shapeID], self.ontology.hasFace, + self.resource["faces_" + shapeID + "_" + str(countpolygonalFace)])) + if face["type"] == "IfcIndexedPolygonalFace": + for constant in face['coordIndex']: + self.g.add( + (self.resource["faces_" + shapeID + "_" + str(countpolygonalFace)], self.ontology.faceValue, + Literal(constant))) + countpolygonalFace += 1 + if face["type"] == "IfcIndexedPolygonalFaceWithVoids": + for constant in face['coordIndex']: + self.g.add( + (self.resource["faces_" + shapeID + "_" + str(countpolygonalFace)], + self.ontology.faceValue, + Literal(constant))) + for constant in face['innerCoordIndices']: + for innerconstant in constant: + self.g.add( + (self.resource["faces_" + shapeID + "_" + str(countpolygonalFace)], self.ontology.faceValueInner, + Literal(innerconstant))) + countpolygonalFace += 1 + if item['type'] == "IfcBooleanClippingResult": + if "operator" in list(item.keys()): + self.g.add((self.resource[shapeID], self.ontology.operator, Literal(item["operator"]))) + if "firstOperand" in list(item.keys()): + self.g.add( + (self.resource["firstplacement_" + shapeID], RDF.type, self.ontology.Placement)) + self.g.add((self.resource[shapeID], self.ontology.hasFirstPlacement, + self.resource["firstplacement_" + shapeID])) + if "sweptArea" in list(item["firstOperand"].keys()): + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.type, + Literal(item["firstOperand"]["sweptArea"]["profileType"]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.name, + Literal(item["firstOperand"]["sweptArea"]["profileName"]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.xcoordinate, + Literal(item["firstOperand"]["sweptArea"]["position"]["location"]["coordinates"][0]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.ycoordinate, + Literal(item["firstOperand"]["sweptArea"]["position"]["location"]["coordinates"][1]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.xDim, + Literal(item["firstOperand"]["sweptArea"]["xDim"]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.yDim, + Literal(item["firstOperand"]["sweptArea"]["yDim"]))) + if "position" in list(item["firstOperand"].keys()): + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.xlocation, + Literal(item["firstOperand"]["position"]["location"]["coordinates"][0]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.ylocation, + Literal(item["firstOperand"]["position"]["location"]["coordinates"][1]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.zlocation, + Literal(item["firstOperand"]["position"]["location"]["coordinates"][2]))) + if "extrudedDirection" in list(item["firstOperand"].keys()): + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.xextrudedDirection, + Literal(item["firstOperand"]["extrudedDirection"]["directionRatios"][0]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.yextrudedDirection, + Literal(item["firstOperand"]["extrudedDirection"]["directionRatios"][1]))) + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.zextrudedDirection, + Literal(item["firstOperand"]["extrudedDirection"]["directionRatios"][2]))) + if "depth" in list(item["firstOperand"].keys()): + self.g.add((self.resource["firstplacement_" + shapeID], self.ontology.depth, + Literal(item["firstOperand"]["depth"]))) + if "secondOperand" in list(item.keys()): + self.g.add( + (self.resource["secondplacement_" + shapeID], RDF.type, self.ontology.Placement)) + self.g.add((self.resource[shapeID], self.ontology.hasSecondPlacement, + self.resource["secondplacement_" + shapeID])) + if "baseSurface" in list(item["secondOperand"].keys()): + if "position" in list(item["secondOperand"]["baseSurface"].keys()): + if "location" in list(item["secondOperand"]["baseSurface"]["position"].keys()): + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.xlocation, + Literal(item["secondOperand"]["baseSurface"]["position"]["location"]["coordinates"][0]))) + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.ylocation, + Literal(item["secondOperand"]["baseSurface"]["position"]["location"]["coordinates"][1]))) + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.zlocation, + Literal(item["secondOperand"]["baseSurface"]["position"]["location"]["coordinates"][2]))) + if "axis" in list(item["secondOperand"]["baseSurface"]["position"].keys()): + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.xaxis, + Literal(item["secondOperand"]["baseSurface"]["position"]["axis"]["directionRatios"][0]))) + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.yaxis, + Literal(item["secondOperand"]["baseSurface"]["position"]["axis"]["directionRatios"][1]))) + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.zaxis, + Literal(item["secondOperand"]["baseSurface"]["position"]["axis"]["directionRatios"][2]))) + if "refDirection" in list(item["secondOperand"]["baseSurface"]["position"].keys()): + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.xrefDirection, + Literal(item["secondOperand"]["baseSurface"]["position"]["refDirection"]["directionRatios"][0]))) + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.yrefDirection, + Literal(item["secondOperand"]["baseSurface"]["position"]["refDirection"]["directionRatios"][1]))) + self.g.add((self.resource["secondplacement_" + shapeID], self.ontology.zrefDirection, + Literal(item["secondOperand"]["baseSurface"]["position"]["refDirection"]["directionRatios"][2]))) + except Exception: + pass + # Create RDF triples + # Serialize and save the RDF graph to a TTL file + file_path = "output.ttl" + self.g.serialize(destination=file_path, format="turtle") \ No newline at end of file diff --git a/ifcParser/main-mapping.py b/ifcParser/main-mapping.py new file mode 100644 index 0000000..ea6b10c --- /dev/null +++ b/ifcParser/main-mapping.py @@ -0,0 +1,25 @@ +from flask import Flask, request, jsonify +import json, ifcJsonParser + +app = Flask(__name__) + +# First route +@app.route('/ifc-mapping', methods=['POST']) +def handle_request1(): + data = request.get_json(force=True) + json_data = json.dumps(data) + print(type(data), type(json_data)) + ifcJsonParser.receive_json(data) + return jsonify({"message": "Response from ifc-mapping"}) + +# Second route +@app.route('/endpoint2', methods=['POST']) +def handle_request2(): + data = request.get_json() + # Process data + # ... + print(data) + return jsonify({"message": "Response from endpoint2"}) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file