Commit a4cc2d0b authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

services: make relationship query compatible with virtuoso

parent 88677def
......@@ -676,210 +676,136 @@ public final class SPARQLQueryBuilder {
public Query retriveResourceRelationships(XURI uri) {
String queryString = format(""
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "prefix deich: <%1$s>\n"
+ "prefix role: <%2$s>\n"
+ "select distinct ?relation ?targetUri ?mainTitle ?subtitle ?partTitle ?partNumber ?publicationYear ?type ?isMainEntry ?isRole\n"
+ "where {\n"
+ "PREFIX deich: <%1$s>\n"
+ "PREFIX role: <%2$s>\n"
+ "SELECT DISTINCT ?relation ?targetUri ?mainTitle ?subtitle ?partTitle ?partNumber ?publicationYear ?type ?isMainEntry ?isRole\n"
+ "WHERE {\n"
+ " {\n"
+ " ?publication deich:publicationOf <%3$s> ;\n"
+ " deich:mainTitle ?mainTitle ;\n"
+ " a deich:Publication .\n"
+ " optional { ?publication deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional { ?publication deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional { ?publication deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional { ?publication deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:publicationOf) as ?relation) .\n"
+ " bind(?publication as ?targetUri) . \n"
+ " bind(iri(deich:Publication) as ?type) . \n"
+ " } union {\n"
+ " OPTIONAL { ?publication deich:subtitle ?subtitle }\n"
+ " OPTIONAL { ?publication deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?publication deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?publication deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:publicationOf) as ?relation) .\n"
+ " BIND(?publication as ?targetUri) . \n"
+ " BIND(iri(deich:Publication) as ?type) . \n"
+ " } UNION {\n"
+ " ?contribution deich:agent <%3$s> ;\n"
+ " deich:role ?relation .\n"
+ " ?withContributor deich:contributor ?contribution ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?withContributor deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?withContributor deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?withContributor deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?withContributor deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " optional {"
+ " OPTIONAL { ?withContributor deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?withContributor deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?withContributor deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?withContributor deich:publicationYear ?publicationYear } \n"
+ " OPTIONAL {"
+ " ?contribution a deich:MainEntry . \n"
+ " bind(true as ?isMainEntry) . \n"
+ " BIND(true as ?isMainEntry) . \n"
+ " } \n"
+ " bind(?withContributor as ?targetUri) . \n"
+ " bind(true as ?isRole) . \n"
+ " } union {\n"
+ " BIND(?withContributor as ?targetUri) . \n"
+ " BIND(true as ?isRole) . \n"
+ " } UNION {\n"
+ " ?workRelation deich:work <%3$s> ;\n"
+ " deich:hasRelationType ?relation .\n"
+ " ?withRelation deich:isRelatedTo ?workRelation ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?withRelation deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?withRelation deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?withRelation deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?withRelation deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(?withRelation as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?withRelation deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?withRelation deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?withRelation deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?withRelation deich:publicationYear ?publicationYear } \n"
+ " BIND(?withRelation as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?seriesParticipation deich:serial <%3$s> .\n"
+ " ?pubInSeries deich:inSerial ?seriesParticipation ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?pubInSeries deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?pubInSeries deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?pubInSeries deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?pubInSeries deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:inSerial) as ?relation) .\n"
+ " bind(?pubInSeries as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?pubInSeries deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?pubInSeries deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?pubInSeries deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?pubInSeries deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:inSerial) as ?relation) .\n"
+ " BIND(?pubInSeries as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?workSeriesParticipation deich:workSeries <%3$s> .\n"
+ " ?workInSeries deich:isPartOfWorkSeries ?workSeriesParticipation ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?workInSeries deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?workInSeries deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?workInSeries deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?workInSeries deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:isPartOfWorkSeries) as ?relation) .\n"
+ " bind(?workInSeries as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?workInSeries deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?workInSeries deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?workInSeries deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?workInSeries deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:isPartOfWorkSeries) as ?relation) .\n"
+ " BIND(?workInSeries as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?instrumentation deich:hasInstrument <%3$s> .\n"
+ " ?workWithInstruments deich:hasInstrumentation ?instrumentation ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?workWithInstruments deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithInstruments deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithInstruments deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?workWithInstruments deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:hasInstrumentation) as ?relation) .\n"
+ " bind(?workWithInstruments as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?workWithInstruments deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?workWithInstruments deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?workWithInstruments deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?workWithInstruments deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:hasInstrumentation) as ?relation) .\n"
+ " BIND(?workWithInstruments as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?pubPart deich:agent <%3$s> ;\n"
+ " deich:role ?relation .\n"
+ " ?withPubPart deich:hasPublicationPart ?pubPart .\n"
+ " ?pubPart a ?type ;\n"
+ " deich:mainTitle ?mainTitle ; \n"
+ " bind(?withPubPart as ?targetUri) . \n"
+ " bind(true as ?isRole) . \n"
+ " } union {\n"
+ " deich:mainTitle ?mainTitle . \n"
+ " BIND(?withPubPart as ?targetUri) . \n"
+ " BIND(true as ?isRole) . \n"
+ " } UNION {\n"
+ " ?pubPart deich:publicationOf <%3$s> .\n"
+ " ?withPubPart deich:hasPublicationPart ?pubPart ;\n"
+ " deich:mainTitle ?mainTitle . \n"
+ " ?pubPart a deich:PublicationPart ;\n"
+ " bind(iri(deich:hasPublicationPart) as ?relation) .\n"
+ " bind(?withPubPart as ?targetUri) . \n"
+ " bind(iri(deich:Publication) as ?type) . \n"
+ " } union {\n"
+ " ?pubPart a deich:PublicationPart .\n"
+ " BIND(iri(deich:hasPublicationPart) as ?relation) .\n"
+ " BIND(?withPubPart as ?targetUri) . \n"
+ " BIND(iri(deich:Publication) as ?type) . \n"
+ " } UNION {\n"
+ " ?workWithSubj deich:subject <%3$s> ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?workWithSubj deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithSubj deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithSubj deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?workWithSubj deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:subject) as ?relation) .\n"
+ " bind(?workWithSubj as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?workWithSubj deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?workWithSubj deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?workWithSubj deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?workWithSubj deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:subject) as ?relation) .\n"
+ " BIND(?workWithSubj as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?workWithCompType deich:hasCompositionType <%3$s> ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?workWithCompType deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithCompType deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithCompType deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?workWithCompType deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:hasCompositionType) as ?relation) .\n"
+ " bind(?workWithCompType as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?workWithCompType deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?workWithCompType deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?workWithCompType deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?workWithCompType deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:hasCompositionType) as ?relation) .\n"
+ " BIND(?workWithCompType as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?workWithGenre deich:genre <%3$s> ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?workWithGenre deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithGenre deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?workWithGenre deich:partNumber ?partNumber . \n"
+ " } \n"
+ " optional {"
+ " ?workWithGenre deich:publicationYear ?publicationYear . \n"
+ " } \n"
+ " bind(iri(deich:genre) as ?relation) .\n"
+ " bind(?workWithGenre as ?targetUri) . \n"
+ " } union {\n"
+ " OPTIONAL { ?workWithGenre deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?workWithGenre deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?workWithGenre deich:partNumber ?partNumber } \n"
+ " OPTIONAL { ?workWithGenre deich:publicationYear ?publicationYear } \n"
+ " BIND(iri(deich:genre) as ?relation) .\n"
+ " BIND(?workWithGenre as ?targetUri) . \n"
+ " } UNION {\n"
+ " ?publWithPlace deich:hasPlaceOfPublication <%3$s> ;\n"
+ " a ?type ;\n"
+ " deich:mainTitle ?mainTitle .\n"
+ " optional {"
+ " ?publWithPlace deich:subtitle ?subtitle . \n"
+ " } \n"
+ " optional {"
+ " ?publWithPlace deich:partTitle ?partTitle . \n"
+ " } \n"
+ " optional {"
+ " ?publWithPlace deich:partNumber ?partNumber . \n"
+ " } \n"
+ " bind(iri(deich:hasPlaceOfPublication) as ?relation) .\n"
+ " bind(?publWithPlace as ?targetUri) . \n"
+ " OPTIONAL { ?publWithPlace deich:subtitle ?subtitle } \n"
+ " OPTIONAL { ?publWithPlace deich:partTitle ?partTitle } \n"
+ " OPTIONAL { ?publWithPlace deich:partNumber ?partNumber } \n"
+ " BIND(iri(deich:hasPlaceOfPublication) as ?relation) .\n"
+ " BIND(?publWithPlace as ?targetUri) . \n"
+ " }\n"
+ " FILTER(STRSTARTS(STR(?type), \"http://data.deichman.no/ontology#\"))"
+ "} order by ?relation", BaseURI.ontology(), BaseURI.role(), uri.getUri());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment