i've to query a set of statements before i create a new version of an object with the same identifier. With the result i analyse the changes and reuse referenced objects, if the haven't changed. But the following query is aweful and very slow. if there are ~ 1000 object versions, it runs about 120 seconds. and i've to import lot more !
Is there a way to query the statements in a more performant way? I know the "OPTIONAL" is bad, but the properties can be empty.
Thanks
PREFIX schema: <https://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX as: <https://www.w3.org/ns/activitystreams#>
CONSTRUCT {
?publication rdf:type ?type ;
schema:about ?about ;
schema:about ?about;
schema:name ?name ;
as:name ?asname ;
as:published ?published ;
as:attributedTo ?attributedTo ;
schema:creativeWorkStatus ?creativeWorkStatus ;
schema:dateCreated ?dateCreated ;
schema:dateModified ?dateModified ;
schema:description ?description ;
schema:identifier ?identifier ;
schema:keywords ?keywords ;
schema:license ?license ;
schema:version ?version .
?about rdf:type ?aboutType ;
schema:name ?aboutName ;
schema:contactPoint ?aboutContactPoint ;
schema:location ?aboutLocation .
?aboutContactPoint rdf:type ?contactPointType ;
schema:email ?contactPointEmail ;
schema:name ?contactPointName ;
schema:telephone?contactPointTelephone .
?aboutLocation rdf:type ?locationType ;
schema:latitude ?locationLatitude ;
schema:longitude ?locationLongitude ;
schema:address ?locationAddress .
# Adress
?locationAddress rdf:type ?addressType ;
schema:addressCountry ?addressCountry ;
schema:addressLocality ?addressLocality ;
schema:streetAddress ?addressStreetAddress ;
schema:postalCode ?addressPostalCode .
}
FROM <http://localhost:8081/camel/fef6dc4b-e1e9-46f5-a34e-8ab5c1600ec4>
WHERE {
?publication rdf:type schema:CreativeWork ;
rdf:type ?type ;
schema:identifier "6472c8bbf6504b56b473a1e6a10fcc8d".
OPTIONAL {?publication schema:name ?name . }
OPTIONAL {?publication as:name ?asname . }
OPTIONAL {?publication as:published ?published . }
OPTIONAL {?publication as:attributedTo ?attributedTo . }
OPTIONAL {?publication schema:creativeWorkStatus ?creativeWorkStatus . }
OPTIONAL {?publication schema:dateCreated ?dateCreated . }
OPTIONAL {?publication schema:dateModified ?dateModified . }
OPTIONAL {?publication schema:description ?description . }
OPTIONAL {?publication schema:identifier ?identifier . }
OPTIONAL {?publication schema:keywords ?keywords . }
OPTIONAL {?publication schema:license ?license . }
OPTIONAL {?publication schema:version ?version . }
OPTIONAL {?publication schema:about ?about . }
# Organization
OPTIONAL {?publication schema:about/rdf:type ?aboutType . }
OPTIONAL {?publication schema:about/schema:name ?aboutName . }
OPTIONAL {?publication schema:about/schema:contactPoint ?aboutContactPoint . }
OPTIONAL {?publication schema:about/schema:location ?aboutLocation . }
# ContactPoint
OPTIONAL {?publication schema:about/schema:contactPoint/rdf:type ?contactPointType . }
OPTIONAL {?publication schema:about/schema:contactPoint/schema:email ?contactPointEmail . }
OPTIONAL {?publication schema:about/schema:contactPoint/schema:name ?contactPointName . }
OPTIONAL {?publication schema:about/schema:contactPoint/schema:telephone?contactPointTelephone . }
# Place
OPTIONAL {?publication schema:about/schema:location/rdf:type ?locationType . }
OPTIONAL {?publication schema:about/schema:location/schema:latitude ?locationLatitude . }
OPTIONAL {?publication schema:about/schema:location/schema:longitude ?locationLongitude . }
OPTIONAL {?publication schema:about/schema:location/schema:address ?locationAddress . }
# Adress
OPTIONAL {?publication schema:about/schema:location/schema:address/rdf:type ?addressType . }
OPTIONAL {?publication schema:about/schema:location/schema:address/schema:addressLocality ?addressLocality . }
OPTIONAL {?publication schema:about/schema:location/schema:address/schema:streetAddress ?addressStreetAddress . }
OPTIONAL {?publication schema:about/schema:location/schema:address/schema:postalCode ?addressPostalCode . }
OPTIONAL {?publication schema:about/schema:location/schema:address/schema:addressCountry ?addressCountry . }
}