diff --git a/owl/prefixes.json b/owl/prefixes.json index 7ec8f4ffb..868176045 100644 --- a/owl/prefixes.json +++ b/owl/prefixes.json @@ -1,5 +1,56 @@ { - +"nstolabel": { + "http://babelnet.org/2.0/": "Babelnet 2.0", + "http://babelnet.org/rdf/": "Babelnet RDF", + "http://purl.org/ontology/af/": "Audio Features Ontology", + "http://xmlns.com/foaf/0.1/": "Friend Of A Friend Ontology", + "http://purl.org/cerif/frapo/":"Funding, Research Administration and Projects Ontology", + "http://www.opengis.net/ont/geosparql#": "The GeoSPARQL Ontology", + "http://purl.org/dpn#":"Data Provider Node ontology", + "http://purl.org/foodontology#": "The FoodOntology Vocabulary for Food Products Description", + "http://purl.org/olia/olia.owl#": "Ontologies of Linguistic Annotation", + "http://viaf.org/ontology/1.1/": "Virtual International Authority File (VIAF) Ontology", + "http://www.w3.org/TR/owl-time#": "OWL Time Ontology", + "http://rdfs.org/scot/ns#": "SCOT (Social Semantic Cloud of Tags) Ontology", + "http://rdfs.co/juso/": "Juso Ontology", + "http://purl.org/pav/": "Provenance, Authoring and Versioning (PAV)", + "http://creativecommons.org/ns#": "Creative Commons Rights Expression Language", + "http://www.opengis.net/kml/2.2#": "Keyhole Markup Language (KML)", + "http://rdfs.co/bevon/": "BEVON: Beverage Ontology", + "http://www.w3.org/ns/lemon/lime#": "Linguistic Metadata Ontology", + "http://www.w3.org/ns/lemon/ontolex#": "Lexicon Model For Ontologies", + "http://wordnet-rdf.princeton.edu/ontology#": "Wordnet Ontology", + "http://www.w3.org/ns/lemon/vartrans#": "Ontolex Variation and Translation Module", + "http://www.w3.org/ns/sosa/":"Sensor, Observation, Sample, and Actuator (SOSA) Ontology", + "http://www.w3.org/2002/07/owl#": "Web Ontology Language 2 Vocabulary", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "The RDF Concepts Vocabulary (RDF)", + "http://www.w3.org/2000/01/rdf-schema#": "The RDF Schema vocabulary (RDFS)", + "http://www.w3.org/2003/01/geo/wgs84_pos#": "W3C Geo Vocabulary", + "http://www.wikidata.org/entity/": "Wikidata Entities", + "http://www.w3.org/ns/prov#": "W3C Provenance Ontology", + "http://www.w3.org/ns/shacl#": "Shapes Constraint Language (SHACL)", + "http://purl.org/goodrelations/v1#": "Good Relations Vocabulary", + "http://www.ontology-of-units-of-measure.org/resource/om-2/": "Ontology of Units of Measurement", + "http://pleiades.stoa.org/places/": "Pleiades Places", + "https://pleiades.stoa.org/places/": "Pleiades Places", + "http://www.w3.org/ns/sparql-service-description#": "SPARQL 1.1 Service Description Vocabulary", + "http://www.w3.org/ns/dcat#": "DCAT Vocabulary", + "http://datashapes.org/dash#": "Data Shapes Vocabulary (DASH)", + "http://purl.org/ontology/mo/": "Music Ontology", + "http://www.w3.org/2003/12/exif/ns#": "EXIF data description vocabulary", + "http://rdfs.org/ns/void#": "Vocabulary of Interlinked Datasets (VoID)", + "http://rdfs.org/ns/void-ext#":"Extensions to the Vocabulary of Interlinked Datasets (VoID-EXT)", + "http://schema.org/": "Schema.org vocabulary", + "https://www.geonames.org/": "GeoNames Ontology", + "http://www.geonames.org/ontology#": "GeoNames Ontology", + "http://www.w3.org/ns/oa#": "Web Annotation Ontology", + "http://www.w3.org/2006/vcard/ns#": "Vcard Vocabulary", + "http://purl.org/ontology/bibo/": "Bibliography Ontology", + "http://www.opengis.net/ont/sf#": "Simple Features Vocabulary", + "http://wikiba.se/ontology#": "Wikibase system ontology", + "http://www.cidoc-crm.org/cidoc-crm/": "CIDOC CRM Ontology", + "http://www.w3.org/2001/XMLSchema#": "XML Schema" +}, "reversed":{ "http://10.0.3.120/download/eproc_FORN_v02.owl#": "eproc", "http://10.0.3.120/download/eproc_FORN_v04.owl#": "eproc2", diff --git a/resources/html/default/js/startscripts.js b/resources/html/default/js/startscripts.js index a3051c043..016589405 100644 --- a/resources/html/default/js/startscripts.js +++ b/resources/html/default/js/startscripts.js @@ -75,6 +75,10 @@ function closeNav() { document.getElementById("mySidenav").style.width = "0"; } +function exportChartJS(){ + saveTextAsFile(JSON.stringify({"xValues":xValues,"yValues":yValues}),"json") +} + function exportGeoJSON(){ if(typeof(feature) !== "undefined"){ saveTextAsFile(JSON.stringify(feature),"geojson") @@ -897,6 +901,62 @@ function setup3dhop(meshurl,meshformat) { }); } +function addRotationControls(box,geometryF){ + geometryF.close(); + + const rotationFolder = geometryF.addFolder("Rotation"); + rotationFolder.add(objects.rotation, 'x', 0, Math.PI).name("X").onChange( + function(){ + yourVar = this.getValue(); + scene.traverse(function(obj){ + if(obj.type === 'Mesh'){ + obj.rotation.x = yourVar; + }}); + }); + rotationFolder.add(objects.rotation, 'y', 0, Math.PI).name("Y").onChange( + function(){ + yourVar = this.getValue(); + scene.traverse(function(obj){ + if(obj.type === 'Mesh'){ + obj.rotation.y = yourVar; + }}); + }); + rotationFolder.add(objects.rotation, 'z', 0, Math.PI).name("Z").onChange( + function(){ + yourVar = this.getValue(); + scene.traverse(function(obj){ + if(obj.type === 'Mesh'){ + obj.rotation.z = yourVar; + }}); + }); + + const scaleFolder = geometryF.addFolder("Scale"); + scaleFolder.add(objects.scale, 'x', 0, 2).name("X").onChange( + function(){ + yourVar = this.getValue(); + scene.traverse(function(obj){ + if(obj.type === 'Mesh'){ + obj.scale.x = yourVar; + }}); + }); + scaleFolder.add(objects.scale, 'y', 0, 2).name("Y").onChange( + function(){ + yourVar = this.getValue(); + scene.traverse(function(obj){ + if(obj.type === 'Mesh'){ + obj.scale.y = yourVar; + }}); + }); + scaleFolder.add(objects.scale, 'z', 0, 2).name("Z").onChange( + function(){ + yourVar = this.getValue(); + scene.traverse(function(obj){ + if(obj.type === 'Mesh'){ + obj.scale.z = yourVar; + }}); + }); +} + function start3dhop(meshurl,meshformat){ init3dhop(); setup3dhop(meshurl,meshformat); @@ -905,30 +965,8 @@ function start3dhop(meshurl,meshformat){ } -let camera, scene, renderer,controls; - -function viewGeometry(geometry) { - const material = new THREE.MeshPhongMaterial({ - color: 0xffffff, - flatShading: true, - vertexColors: THREE.VertexColors, - wireframe: false - }); - const mesh = new THREE.Mesh(geometry, material); - scene.add(mesh); -} - -function initThreeJS(domelement,verts,meshurls) { - scene = new THREE.Scene(); - minz=Number.MAX_VALUE - maxz=Number.MIN_VALUE - miny=Number.MAX_VALUE - maxy=Number.MIN_VALUE - minx=Number.MAX_VALUE - maxx=Number.MIN_VALUE - vertarray=[] - console.log(verts) - var svgShape = new THREE.Shape(); +function prepareAnnotationFromJSON(verts,annotations){ + var svgShape = new THREE.Shape(); first=true for(vert of verts){ if(first){ @@ -959,40 +997,128 @@ function initThreeJS(domelement,verts,meshurls) { miny=vert["x"] } } + var extrudedGeometry = new THREE.ExtrudeGeometry(svgShape, {depth: maxz-minz, bevelEnabled: false}); + extrudedGeometry.computeBoundingBox() + const material = new THREE.MeshBasicMaterial( { color: 0xFFFFFF, wireframe:true } ); + const mesh = new THREE.Mesh( extrudedGeometry, material ); + annotations.add(mesh) + return annotations +} + +let camera, scene, renderer,controls,axesHelper; + +function initThreeJS(domelement,verts,meshurls) { + scene = new THREE.Scene(); + minz=Number.MAX_VALUE + maxz=Number.MIN_VALUE + miny=Number.MAX_VALUE + maxy=Number.MIN_VALUE + minx=Number.MAX_VALUE + maxx=Number.MIN_VALUE + vertarray=[] + annotations=new THREE.Group(); + const objects=new THREE.Group(); + console.log(verts) + var svgShape = new THREE.Shape(); + first=true + height=500 + width=480 + annotations=prepareAnnotationFromJSON(verts,annotations) + const gui = new dat.GUI({autoPlace: false}) + gui.domElement.id="gui" + $("#threejsnav").append($(gui.domElement)) + const geometryFolder = gui.addFolder("Mesh"); + geometryFolder.open(); + const lightingFolder = geometryFolder.addFolder("Lighting"); + const geometryF = geometryFolder.addFolder("Geometry"); + geometryF.open(); + renderer = new THREE.WebGLRenderer( { antialias: false } ); + renderer.setPixelRatio( window.devicePixelRatio ); + renderer.setSize( width, height); + document.getElementById(domelement).appendChild( renderer.domElement ); + bbox=null if(meshurls.length>0){ - var loader = new THREE.PLYLoader(); - loader.load(meshurls[0], viewGeometry); + if(meshurls[0].includes(".ply")){ + var loader = new THREE.PLYLoader(); + loader.load(meshurls[0], function(object){ + const material = new THREE.MeshPhongMaterial({ + color: 0xffffff, + flatShading: true, + vertexColors: THREE.VertexColors, + wireframe: false + }); + const mesh = new THREE.Mesh(object, material); + objects.add(mesh); + scene.add(objects); + addRotationControls(object,geometryF,objects) + }); + }else if(meshurls[0].includes(".obj")){ + var loader= new THREE.OBJLoader(); + loader.load(meshurls[0],function ( object ) {objects.add(object);scene.add(objects); addRotationControls(object,geometryF,objects)}) + }else if(meshurls[0].includes(".nxs") || meshurls[0].includes(".nxz")){ + var nexus_obj=new NexusObject(meshurls[0],function(){},renderNXS,renderer); + objects.add(nexus_obj) + scene.add(objects); + addRotationControls(nexus_obj,geometryF,objects) + }else if(meshurls[0].includes(".gltf")){ + var loader = new THREE.GLTFLoader(); + loader.load(meshurls[0], function ( gltf ) + { + box = gltf.scene; + box.position.x = 0; + box.position.y = 0; + objects.add(box) + scene.add(objects); + addRotationControls(box,geometryF,objects) + }); + } } - camera = new THREE.PerspectiveCamera(90,window.innerWidth / window.innerHeight, 0.1, 150 ); + //camera = new THREE.PerspectiveCamera(90,window.innerWidth / window.innerHeight, 0.1, 150 ); + camera = new THREE.PerspectiveCamera(90,width / height, 0.1, 2000 ); scene.add(new THREE.AmbientLight(0x222222)); var light = new THREE.DirectionalLight(0xffffff, 1); light.position.set(20, 20, 0); scene.add(light); - var axesHelper = new THREE.AxesHelper( Math.max(maxx, maxy, maxz)*4 ); + lightingFolder.add(light.position, "x").min(-5).max(5).step(0.01).name("X Position") + lightingFolder.add(light.position, "y").min(-5).max(5).step(0.01).name("Y Position") + lightingFolder.add(light.position, "z").min(-5).max(5).step(0.01).name("Z Position") + axesHelper = new THREE.AxesHelper( Math.max(1000, 1000, 1000) ); scene.add( axesHelper ); console.log("Depth: "+(maxz-minz)) - var extrudedGeometry = new THREE.ExtrudeGeometry(svgShape, {depth: maxz-minz, bevelEnabled: false}); - extrudedGeometry.computeBoundingBox() - centervec=new THREE.Vector3() - extrudedGeometry.boundingBox.getCenter(centervec) - console.log(centervec) - const material = new THREE.MeshBasicMaterial( { color: 0xFFFFFF, wireframe:true } ); - const mesh = new THREE.Mesh( extrudedGeometry, material ); - scene.add( mesh ); - renderer = new THREE.WebGLRenderer( { antialias: false } ); - renderer.setPixelRatio( window.devicePixelRatio ); - renderer.setSize( 480, 500 ); - document.getElementById(domelement).appendChild( renderer.domElement ); - controls = new THREE.OrbitControls( camera, renderer.domElement ); - controls.target.set( centervec.x,centervec.y,centervec.z ); - camera.position.x= centervec.x - camera.position.y= centervec.y - camera.position.z = centervec.z+10; - controls.maxDistance= Math.max(maxx, maxy, maxz)*5 + scene.add( annotations ); + centervec=new THREE.Vector3() + controls = new THREE.OrbitControls( camera, renderer.domElement ); + //controls.target.set( centervec.x,centervec.y,centervec.z ); + controls.target.set( 0,0,0 ); + camera.position.x= 0 + camera.position.y= 0 + camera.position.z = 150; + controls.maxDistance= Math.max(1000, 1000, 1000) controls.update(); + const updateCamera = () => { + camera.updateProjectionMatrix(); + } + const cameraFolder = geometryFolder.addFolder("Camera"); + cameraFolder.add(camera, 'fov', 1, 180).name('Zoom').onChange(updateCamera); + cameraFolder.add(camera.position, 'x').min(-500).max(500).step(5).name("X Position").onChange(updateCamera); + cameraFolder.add(camera.position, 'y').min(-500).max(500).step(5).name("Y Position").onChange(updateCamera); + cameraFolder.add(camera.position, 'z').min(-500).max(500).step(5).name("Z Position").onChange(updateCamera); + gui.add(objects, 'visible').name('Meshes') + gui.add(annotations, 'visible').name('Annotations') + gui.add(axesHelper, 'visible').name('Axis Helper') + if(meshurls.length>0 && (meshurls[0].includes(".nxs") || meshurls[0].includes(".nxz"))){ + renderNXS() + } animate() } +function renderNXS(){ + console.log(renderer) + Nexus.beginFrame(renderer.getContext()); + renderer.render( scene, camera ); + Nexus.endFrame(renderer.getContext()); +} + function animate() { requestAnimationFrame( animate ); controls.update(); @@ -1053,7 +1179,7 @@ function formatHTMLTableForPropertyRelations(propuri,result,propicon){ if(result["from"][instance]=="instancecount"){ continue; } - dialogcontent+="\"Class\"/"+shortenURI(result["from"][instance])+"" + dialogcontent+="\"Class\"/"+shortenURI(result["from"][instance])+"" dialogcontent+="\"Instance\"/"+shortenURI(propuri)+"" // } } @@ -1063,7 +1189,7 @@ function formatHTMLTableForPropertyRelations(propuri,result,propicon){ continue; } dialogcontent+="\"Class\"/"+shortenURI(propuri)+"" - dialogcontent+="\"Instance\"/"+shortenURI(result["to"][instance])+"" + dialogcontent+="\"Instance\"/"+shortenURI(result["to"][instance])+"" // } } dialogcontent+="" @@ -1072,34 +1198,34 @@ function formatHTMLTableForPropertyRelations(propuri,result,propicon){ } function determineTableCellLogo(uri){ - result="" + result="" logourl="" finished=false if(uri in labelproperties){ - result+="\"Label" + result+="\"Label" logourl=iconprefix+"labelproperty.png" finished=true } if(!finished){ for(ns in annotationnamespaces){ if(uri.includes(annotationnamespaces[ns])){ - result+="\"Annotation" + result+="\"Annotation" logourl=iconprefix+"annotationproperty.png" finished=true } } } if(!finished && uri in geoproperties && geoproperties[uri]=="ObjectProperty"){ - result+="\"Geo" + result+="\"Geo" logourl=iconprefix+"geoobjectproperty.png" }else if(!finished && uri in geoproperties && geoproperties[uri]=="DatatypeProperty"){ - result+="\"Geo" + result+="\"Geo" logourl=iconprefix+"geodatatypeproperty.png" }else if(!finished){ - result+="\"Object" + result+="\"Object" logourl=iconprefix+"objectproperty.png" } - result+=shortenURI(uri)+"" + result+=""+shortenURI(uri)+"" return [result,logourl] } @@ -1114,9 +1240,9 @@ function formatHTMLTableForClassRelations(result,nodeicon,nodelabel,nodeid){ if(instance=="instancecount"){ continue; } - dialogcontent+="\"Class\"/"+shortenURI(instance)+"" + dialogcontent+="\"Class\"/"+shortenURI(instance)+"" dialogcontent+=determineTableCellLogo(res)[0] - dialogcontent+="\"Instance\"/"+nodelabel+"" + dialogcontent+="\"Instance\"/"+nodelabel+"" } } for(res in result["to"]){ @@ -1124,9 +1250,9 @@ function formatHTMLTableForClassRelations(result,nodeicon,nodelabel,nodeid){ if(instance=="instancecount"){ continue; } - dialogcontent+="\"Instance\"/"+nodelabel+"" + dialogcontent+="\"Instance\"/"+nodelabel+"" dialogcontent+=determineTableCellLogo(res)[0] - dialogcontent+="\"Class\"/"+shortenURI(instance)+"" + dialogcontent+="\"Class\"/"+shortenURI(instance)+"" } } dialogcontent+="" @@ -1162,7 +1288,7 @@ function formatHTMLTableForResult(result,nodeicon){ if((resitem+"").startsWith("http")){ dialogcontent+="
  • "+shortenURI(resitem)+" ["+result[res][resitem]+"]
  • " }else if(resitem!="instancecount"){ - dialogcontent+="
  • "+resitem+"
  • " + dialogcontent+="
  • "+result[res][resitem]+"
  • " } } dialogcontent+="" diff --git a/util/doc/ontdocgeneration.py b/util/doc/ontdocgeneration.py index e551fbb51..585d24399 100644 --- a/util/doc/ontdocgeneration.py +++ b/util/doc/ontdocgeneration.py @@ -28,6 +28,7 @@ from ..export.data.exporter.rdf.voidexporter import VoidExporter listthreshold=5 +maxlistthreshold=1500 jsonindent=2 @@ -323,6 +324,8 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"): self.licensehtml=curlicense res=self.getPropertyRelations(self.graph, outpath) voidstats["http://rdfs.org/ns/void#properties"]=res["preds"] + voidstats["http://ldf.fi/void-ext#propertyClasses"] = res["predclasses"] + voidstats["http://ldf.fi/void-ext#averagePropertyIRILength"] = res["avgpredlen"] voidstats["http://rdfs.org/ns/void#distinctObjects"]=res["objs"] predmap=res["predmap"] dsname=self.datasettitle @@ -340,28 +343,59 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"): subjectstorender.add(URIRef(voidds)) nonnscount={} instancecount={} + literaltypes={} + blanknodes=set() + literallangs=set() + literals=set() + irirefs=0 + literallength=0 + literalcount=0 + subjectlength=0 + objectlength=0 + subjectcounter=0 + objectcounter=0 for sub in self.graph.subjects(None,None,True): #QgsMessageLog.logMessage(str(prefixnamespace)+" "+str(sub), "OntdocGeneration", Qgis.Info) - if(prefixnamespace in sub and (isinstance(sub,URIRef)) or isinstance(sub,BNode)): + if (prefixnamespace in sub and (isinstance(sub, URIRef)) or isinstance(sub, BNode)): subjectstorender.add(sub) - label=DocUtils.shortenURI(str(sub)) - restriction=False + label = DocUtils.shortenURI(str(sub)) + restriction = False self.graph.add((sub, URIRef("http://rdfs.org/ns/void#inDataset"), URIRef(voidds))) - self.addAdditionalTriplesForInd(self.graph,sub,self.tobeaddedPerInd) + if isinstance(sub, BNode): + blanknodes.add(str(sub)) + irirefs += 1 + subjectcounter += 1 + subjectlength += len(str(sub)) for tup in self.graph.predicate_objects(sub): + if isinstance(tup[1], Literal): + if tup[1].datatype != None: + if str(tup[1].datatype) not in literaltypes: + literaltypes[str(tup[1].datatype)] = set() + literaltypes[str(tup[1].datatype)].add(str(tup[0])) + if tup[1].language != None: + literallangs.add(str(tup[1].language)) + literallength += len(str(tup[1])) + literals.add(str(tup[1])) + literalcount += 1 + elif isinstance(tup[1], BNode): + blanknodes.add(str(tup[1])) + else: + objectlength += len(str(tup[1])) + objectcounter += 1 + irirefs += 1 if str(tup[0]) in SPARQLUtils.labelproperties: labeltouri[str(tup[1])] = str(sub) - uritolabel[str(sub)] = {"label":str(tup[1])} - label=str(tup[1]) - elif str(tup[0])==self.typeproperty: + uritolabel[str(sub)] = {"label": str(tup[1])} + label = str(tup[1]) + elif str(tup[0]) == self.typeproperty: if str(tup[1]) not in instancecount: - instancecount[str(tup[1])]=0 - instancecount[str(tup[1])]+=1 + instancecount[str(tup[1])] = 0 + instancecount[str(tup[1])] += 1 elif str(tup[1]) == "http://www.w3.org/2002/07/owl#Restriction": - restriction = True + restriction = True elif str(tup[0]) == "http://www.w3.org/2000/01/rdf-schema#subClassOf": - ressubcls=str(tup[1]) + ressubcls = str(tup[1]) if isinstance(tup[1], URIRef) and prefixnamespace not in str(tup[1]): ns = DocUtils.shortenURI(str(tup[1]), True) if str(tup[0]) not in nonnscount: @@ -369,11 +403,20 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"): if ns not in nonnscount[str(tup[0])]: nonnscount[str(tup[0])][ns] = 0 nonnscount[str(tup[0])][ns] += 1 - if isinstance(sub,BNode) and restriction: + if isinstance(sub, BNode) and restriction: self.graph.add((sub, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), - Literal(label + " [Restriction]", lang="en"))) + Literal(label + " [Restriction]", lang="en"))) voidstats["http://rdfs.org/ns/void#distinctSubjects"] += 1 voidstats["http://rdfs.org/ns/void#entities"] = len(subjectstorender) + voidstats["http://ldf.fi/void-ext#languages"] = len(literallangs) + voidstats["http://ldf.fi/void-ext#distinctBlankNodes"] = len(blanknodes) + voidstats["http://ldf.fi/void-ext#datatypes"] = len(literaltypes.keys()) + voidstats["http://ldf.fi/void-ext#distinctLiterals"] = len(literals) + voidstats["http://ldf.fi/void-ext#averageSubjectIRILength"] = int(subjectlength / subjectcounter) + voidstats["http://ldf.fi/void-ext#averageObjectIRILength"] = int(objectlength / objectcounter) + voidstats["http://ldf.fi/void-ext#averageLiteralLength"] = int(literallength / literalcount) + voidstats["http://ldf.fi/void-ext#distinctIRIReferences"] = voidstats["http://rdfs.org/ns/void#distinctSubjects"] + res["preds"] + res["objs"] + voidstats["http://ldf.fi/void-ext#distinctRDFNodes"] = len(blanknodes) + len(literals) + voidstats["http://ldf.fi/void-ext#distinctIRIReferences"] if os.path.exists(outpath + corpusid + '_search.js'): try: with open(outpath + corpusid + '_search.js', 'r', encoding='utf-8') as f: @@ -404,9 +447,10 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"): voidstats["http://rdfs.org/ns/void#classes"]=len(classidset) voidstats["http://rdfs.org/ns/void#triples"] = len(self.graph) voidgraph = VoidExporter.createVoidDataset(self.datasettitle, prefixnamespace, self.deploypath, self.outpath, - self.licenseuri, self.modtime, self.labellang, voidstats, tree, - predmap, nonnscount, instancecount, self.startconcept) - self.voidstatshtml=VoidExporter.toHTML(voidstats,self.deploypath) + self.licenseuri, self.modtime, self.labellang, voidstats, + subjectstorender, self.prefixes, tree, predmap, nonnscount, + instancecount, self.startconcept) + self.voidstatshtml = VoidExporter.toHTML(voidstats, self.deploypath) self.graph+=voidgraph["graph"] subjectstorender.update(voidgraph["subjects"]) with open(outpath + "style.css", 'w', encoding='utf-8') as f: @@ -461,7 +505,6 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"): self.checkGeoInstanceAssignment(uritotreeitem) classlist=self.assignGeoClassesToTree(tree) if self.generatePagesForNonNS: - #self.detectURIsConnectedToSubjects(subjectstorender, self.graph, prefixnamespace, corpusid, outpath, self.license,prefixnamespace) self.getSubjectPagesForNonGraphURIs(nonnsmap, self.graph, prefixnamespace, corpusid, outpath, self.license,prefixnamespace,uritotreeitem,labeltouri) with open(outpath + corpusid + "_classtree.js", 'w', encoding='utf-8') as f: f.write("var tree=" + json.dumps(tree, indent=jsonindent)) @@ -594,28 +637,34 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"): f.write(indexhtml) f.close() - def getPropertyRelations(self,graph,outpath): - predicates= {} - predicatecounter=0 - objects=set() - for pred in graph.predicates(None,None,True): - predicates[pred]={"from":set(),"to":set(),"triples":0} + def getPropertyRelations(self, graph, outpath): + predicates = {} + predicatecounter = 0 + predicatelength = 0 + predicateClasses = 0 + objects = set() + for pred in graph.predicates(None, None, True): + predicates[pred] = {"from": set(), "to": set(), "triples": 0} for tup in graph.subject_objects(pred): - for item in graph.objects(tup[0],URIRef(self.typeproperty),True): + if str(tup[0]) == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": + predicateClasses += 1 + for item in graph.objects(tup[0], URIRef(self.typeproperty), True): predicates[pred]["from"].add(item) - for item in graph.objects(tup[1], URIRef(self.typeproperty),True): + for item in graph.objects(tup[1], URIRef(self.typeproperty), True): predicates[pred]["to"].add(item) objects.add(str(tup[1])) - predicates[pred]["triples"]+=1 - predicates[pred]["from"]=list(predicates[pred]["from"]) + predicates[pred]["triples"] += 1 + predicates[pred]["from"] = list(predicates[pred]["from"]) predicates[pred]["to"] = list(predicates[pred]["to"]) - predicatecounter+=1 + predicatecounter += 1 + predicatelength += len(str(pred)) if self.createVOWL: - OWL2VOWL().convertOWL2MiniVOWL(graph,outpath,"minivowl_result.js",predicates) - with open(outpath+"proprelations.js", 'w', encoding='utf-8') as f: - f.write("var proprelations="+json.dumps(predicates)) + OWL2VOWL().convertOWL2MiniVOWL(graph, outpath, "minivowl_result.js", predicates) + with open(outpath + "proprelations.js", 'w', encoding='utf-8') as f: + f.write("var proprelations=" + json.dumps(predicates)) f.close() - return {"preds":predicatecounter,"objs":len(objects),"predmap":predicates} + return {"preds": predicatecounter, "avgpredlen": str(int(predicatelength / predicatecounter)), + "predclasses": predicateClasses, "objs": len(objects), "predmap": predicates} def createCollections(self,graph,namespace): classToInstances={} @@ -1163,42 +1212,6 @@ def polygonToPath(self, svg): return svg.replace("", "") - def detectURIsConnectedToSubjects(self,subjectstorender,graph,prefixnamespace,corpusid,outpath,curlicense,baseurl): - uristorender={} - uritolabel={} - for sub in subjectstorender: - onelabel="" - label=None - added=[] - for tup in graph.predicate_objects(sub): - if str(tup[0]) in SPARQLUtils.labelproperties: - if tup[1].language == self.labellang: - label = str(tup[1]) - break - onelabel = str(tup[1]) - if isinstance(tup[1],URIRef) and prefixnamespace not in str(tup[1]) and "http://www.w3.org/1999/02/22-rdf-syntax-ns#" not in str(tup[1]): - if str(tup[1]) not in uristorender: - uristorender[str(tup[1])]={} - if str(tup[0]) not in uristorender[str(tup[1])]: - uristorender[str(tup[1])][str(tup[0])]=[] - for objtup in graph.predicate_objects(tup[1]): - if str(objtup[0]) in SPARQLUtils.labelproperties: - uritolabel[str(tup[1])] = str(objtup[1]) - toadd={"sub":sub,"label":onelabel} - added.append(toadd) - uristorender[str(tup[1])][str(tup[0])].append(toadd) - for item in added: - if label!=None: - item["label"]=label - else: - item["label"]=onelabel - for uri in uristorender: - thelabel="" - if uri in uritolabel: - thelabel=uritolabel[uri] - self.createHTML(outpath+"nonns_"+DocUtils.shortenURI(uri)+".html", None, URIRef(uri), baseurl, graph.subject_predicates(URIRef(uri),True), graph, str(corpusid) + "_search.js", str(corpusid) + "_classtree.js", None, self.license, subjectstorender, Graph(),None,True,thelabel) - - def getAccessFromBaseURL(self,baseurl,savepath): #QgsMessageLog.logMessage("Checkdepth: " + baseurl+" "+savepath.replace(baseurl, ""), "OntdocGeneration", Qgis.Info) @@ -1312,7 +1325,10 @@ def createHTML(self,savepath, predobjs, subject, baseurl, subpreds, graph, searc if len(predobjmap[tup])>1: thetable+="" if len(predobjmap[tup]) > listthreshold: @@ -1387,7 +1405,10 @@ def createHTML(self,savepath, predobjs, subject, baseurl, subpreds, graph, searc if len(subpredsmap[tup]) > 1: tablecontents += "" if len(subpredsmap[tup]) > listthreshold: diff --git a/util/export/data/exporter/rdf/voidexporter.py b/util/export/data/exporter/rdf/voidexporter.py index a24ebb163..7371d8dad 100644 --- a/util/export/data/exporter/rdf/voidexporter.py +++ b/util/export/data/exporter/rdf/voidexporter.py @@ -7,9 +7,8 @@ class VoidExporter: @staticmethod - def createVoidDataset(dsname,prefixnamespace,deploypath,outpath,licenseuri,modtime,language,stats,classtree=None,propstats=None,nonnscount=None,objectmap=None,startconcept=None): + def createVoidDataset(dsname,prefixnamespace,deploypath,outpath,licenseuri,modtime,language,stats,subjectstorender,prefixes,classtree=None,propstats=None,nonnscount=None,objectmap=None,startconcept=None): g=Graph() - subjects = set() if dsname==None or dsname=="": dsname="dataset" voidds=prefixnamespace+dsname @@ -38,18 +37,19 @@ def createVoidDataset(dsname,prefixnamespace,deploypath,outpath,licenseuri,modti URIRef("http://www.w3.org/ns/formats/Turtle"))) g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#feature"), URIRef("http://www.w3.org/ns/formats/RDFa"))) - if startconcept!=None: - g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#rootResource"), URIRef(startconcept))) - g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#exampleResource"), URIRef(startconcept))) + if startconcept!=None and startconcept!="": + g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#rootResource"), URIRef(startconcept.replace("index.html","")))) + g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#exampleResource"), URIRef(startconcept.replace("index.html","")))) for stat in stats: - g.add((URIRef(voidds),URIRef(stat),Literal(stats[stat],datatype="http://www.w3.org/2001/XMLSchema#integer"))) + g.add((URIRef(voidds), URIRef(stat),Literal(stats[stat], datatype="http://www.w3.org/2001/XMLSchema#integer"))) g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#uriSpace"), Literal(prefixnamespace,datatype="http://www.w3.org/2001/XMLSchema#string"))) for ns_prefix, namespace in g.namespaces(): g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#vocabulary"),URIRef(namespace))) if str(namespace) in DocConfig.namespaceToTopic: for entry in DocConfig.namespaceToTopic[str(namespace)]: - g.add((URIRef(voidds), URIRef("http://purl.org/dc/terms/subject"),URIRef(entry))) + g.add((URIRef(voidds), URIRef("http://purl.org/dc/terms/subject"),URIRef(entry["uri"]))) + g.add((URIRef(entry["uri"]),URIRef("http://www.w3.org/2000/01/rdf-schema#label"),Literal(entry["label"],lang="en"))) for pred in propstats: cururi=voidds+"_"+DocUtils.shortenURI(pred) g.add((URIRef(voidds),URIRef("http://rdfs.org/ns/void#propertyPartition"),URIRef(cururi))) @@ -57,35 +57,29 @@ def createVoidDataset(dsname,prefixnamespace,deploypath,outpath,licenseuri,modti g.add((URIRef(cururi), URIRef("http://www.w3.org/2000/01/rdf-schema#label"),Literal("Property Partition: " + str(DocUtils.shortenURI(pred)), lang="en"))) g.add((URIRef(cururi),URIRef("http://rdfs.org/ns/void#property"),URIRef(pred))) g.add((URIRef(cururi),URIRef("http://rdfs.org/ns/void#triples"),Literal(str(propstats[pred]["triples"]),datatype="http://www.w3.org/2001/XMLSchema#integer"))) - subjects.add(URIRef(cururi)) + subjectstorender.add(URIRef(cururi)) for item in classtree["core"]["data"]: - if item["type"] == "class": - cururi = voidds + "_" + DocUtils.shortenURI(item["id"]) + if item["type"]=="class": + cururi = voidds +"_"+ DocUtils.shortenURI(item["id"]) g.add((URIRef(voidds), URIRef("http://rdfs.org/ns/void#classPartition"), URIRef(cururi))) - g.add((URIRef(cururi), URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), - URIRef("http://rdfs.org/ns/void#Dataset"))) - g.add((URIRef(cururi), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), - Literal("Class Partition: " + str(DocUtils.shortenURI(item["id"])), lang="en"))) + g.add((URIRef(cururi), URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),URIRef("http://rdfs.org/ns/void#Dataset"))) + g.add((URIRef(cururi), URIRef("http://www.w3.org/2000/01/rdf-schema#label"),Literal("Class Partition: " + str(DocUtils.shortenURI(item["id"])),lang="en"))) g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#class"), URIRef(item["id"]))) if item["id"] in objectmap: - g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#entities"), - Literal(str(objectmap[item["id"]]), datatype="http://www.w3.org/2001/XMLSchema#integer"))) - subjects.add(URIRef(cururi)) + g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#entities"),Literal(str(objectmap[item["id"]]), datatype="http://www.w3.org/2001/XMLSchema#integer"))) + #subjectstorender.add(URIRef(cururi)) for prop in nonnscount: for ns in nonnscount[prop]: - cururi = voidds + "_" + DocUtils.shortenURI(ns) - g.add((URIRef(cururi), URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), - URIRef("http://rdfs.org/ns/void#Linkset"))) - g.add((URIRef(cururi), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), - Literal("Linkset: " + str(DocUtils.shortenURI(voidds)) + " - " + str(DocUtils.shortenURI(ns)), - lang="en"))) - g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#subjectsTarget"), URIRef(voidds))) - g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#objectsTarget"), URIRef(ns))) - g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#linkPredicate"), URIRef(prop))) - g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#triples"),Literal(str(nonnscount[prop][ns]), datatype="http://www.w3.org/2001/XMLSchema#integer"))) - subjects.add(URIRef(cururi)) + cururi=voidds+"_"+ns.replace("http://","").replace("https://","").replace("/","_").replace("#","_") + g.add((URIRef(cururi), URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),URIRef("http://rdfs.org/ns/void#Linkset"))) + g.add((URIRef(cururi), URIRef("http://www.w3.org/2000/01/rdf-schema#label"),Literal("Linkset: "+str(DocUtils.shortenURI(voidds))+" - "+str(DocUtils.getLabelForObject(URIRef(ns),g,prefixes)),lang="en"))) + g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#subjectsTarget"),URIRef(voidds))) + g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#objectsTarget"),URIRef(ns))) + g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#linkPredicate"),URIRef(prop))) + g.add((URIRef(cururi), URIRef("http://rdfs.org/ns/void#triples"),Literal(str(nonnscount[prop][ns]),datatype="http://www.w3.org/2001/XMLSchema#integer"))) + subjectstorender.add(URIRef(cururi)) g.serialize(outpath+"/void.ttl", encoding="utf-8") - return {"graph":g,"subjects":subjects} + return {"graph":g,"subjects":subjectstorender} @staticmethod def toHTML(stats,deploypath):