added indexing of collection data with dedicated query

This commit is contained in:
Enrico Ottonello 2020-06-15 12:10:59 +02:00
parent 06995feefa
commit 42c3f5e885
3 changed files with 149 additions and 5 deletions

View File

@ -360,6 +360,10 @@ public class GraphDBClient {
final ClassPathResource queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql");
String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name());
runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId);
// List<String> collectionResourceId = runSPQRLQuery.selectCollectionId(datasource, collectionId);
// final ClassPathResource selectCollectionTemplateRes = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql");
// String selectCollectionTemplate = IOUtils.toString(selectCollectionTemplateRes.getInputStream(), StandardCharsets.UTF_8.name());
// runSPQRLQuery.executeMultipleQueryGraph(selectCollectionTemplate, collectionResourceId, datasource, collectionId);
}catch(Throwable e){
log.error(e);
throw new AriadnePlusPublisherException(e);

View File

@ -161,7 +161,7 @@ public class RunSPARQLQueryService {
}
public List<String> selectRecordIds(String datasource, String collectionId){
log.debug("Retrieving recordIds from GraphDB ...");
log.debug("Retrieving record Ids from GraphDB ...");
String queryTemplate = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"select * \n" +
"from <https://ariadne-infrastructure.eu/api_________::ariadne_plus::%datasource::%collectionId>\n" +
@ -169,9 +169,25 @@ public class RunSPARQLQueryService {
"\t?recordId rdf:type <https://www.ariadne-infrastructure.eu/resource/ao/cat/1.1/AO_Individual_Data_Resource> .\n" +
"} \n";
String query = queryTemplate.replaceAll("%datasource", datasource).replaceAll("%collectionId", collectionId);
return executeSelect(query);
}
public List<String> selectCollectionId(String datasource, String collectionId){
log.debug("Retrieving collection Id from GraphDB ...");
String queryTemplate = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"select * \n" +
"from <https://ariadne-infrastructure.eu/api_________::ariadne_plus::%datasource::%collectionId>\n" +
"where { \n" +
"\t?recordId rdf:type <https://www.ariadne-infrastructure.eu/resource/ao/cat/1.1/AO_Collection> .\n" +
"} \n";
String query = queryTemplate.replaceAll("%datasource", datasource).replaceAll("%collectionId", collectionId);
return executeSelect(query);
}
private List<String> executeSelect(String query){
openConnection();
String jsonRecord = null;
List<String> recordIds = new ArrayList<>();
List<String> results = new ArrayList<>();
try {
log.debug("Started at: "+Calendar.getInstance().getTime().toString());
TupleQuery selectQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
@ -180,16 +196,16 @@ public class RunSPARQLQueryService {
while (selectQueryResult.hasNext()) {
BindingSet recordSet = selectQueryResult.next();
org.eclipse.rdf4j.model.Value recordIdValue = recordSet.getValue("recordId");
recordIds.add(recordIdValue.stringValue());
results.add(recordIdValue.stringValue());
counter++;
}
log.debug("Total recordIds retrieved: "+counter);
log.debug("Total records retrieved: "+counter);
log.debug("Finished at: "+Calendar.getInstance().getTime().toString());
} catch(Exception e){
e.printStackTrace();
} finally{
closeConnection();
}
return recordIds;
return results;
}
}

View File

@ -0,0 +1,124 @@
PREFIX aocat: <https://www.ariadne-infrastructure.eu/resource/ao/cat/1.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX aoprop: <https://www.ariadne-infrastructure.eu/property/>
PREFIX onto: <http://www.ontotext.com/>
PREFIX ariadneplus: <https://ariadne-infrastructure.eu/aocat/>
PREFIX time: <http://www.w3.org/2006/time#>
CONSTRUCT {
%record aoprop:identifier %record .
%record aoprop:originalId ?originalId .
%record aoprop:issued ?issued .
%record aoprop:modified ?modified .
%record aoprop:partOf ?partOf .
%record aoprop:creator ?creator .
?creator aoprop:name ?creatorName .
?creator aoprop:email ?creatorEmail .
%record aoprop:contributor ?contributor .
?contributor aoprop:name ?contributorName .
?contributor aoprop:email ?contributorEmail .
%record aoprop:legalResponsible ?legalResponsible .
?legalResponsible aoprop:name ?legalResponsibleName .
?legalResponsible aoprop:email ?legalResponsibleEmail .
%record aoprop:owner ?owner .
?owner aoprop:name ?ownerName .
?owner aoprop:email ?ownerEmail .
%record aoprop:publisher ?publisher .
?publisher aoprop:name ?publisherName .
?publisher aoprop:email ?publisherEmail .
%record aoprop:accessPolicy ?accessPolicy .
%record aoprop:accessRights ?accessRights .
%record aoprop:landingPage ?landingPage .
%record aoprop:spatialRegion ?spatialRegion .
?spatialRegion aoprop:placeName ?spatialPlaceName .
?spatialRegion aoprop:spatialCoordinateSystem ?spatialCoordinateSystem .
%record aoprop:spatialRegionPoint ?spatialRegionPoint .
?spatialRegionPoint aoprop:lat ?spatialLocationLat .
?spatialRegionPoint aoprop:lon ?spatialLocationLon .
%record aoprop:spatialRegionBox ?spatialRegionBox .
?spatialRegionBox aoprop:boxMaxLat ?spatialLocationBBMaxLat .
?spatialRegionBox aoprop:boxMaxLon ?spatialLocationBBMaxLon .
?spatialRegionBox aoprop:boxMinLat ?spatialLocationBBMinLat .
?spatialRegionBox aoprop:boxMinLon ?spatialLocationBBMinLon .
%record aoprop:uri ?temporal .
?temporal aoprop:periodName ?temporalPeriodName .
?temporal aoprop:from ?temporalFrom .
?temporal aoprop:until ?temporalUntil .
%record aoprop:uri ?temporalNative .
?temporalNative aoprop:periodName ?temporalNativePeriodName .
%record aoprop:archeologicalResourceType ?archeologicalResourceType .
?archeologicalResourceType aoprop:name ?archeologicalResourceTypeName .
%record aoprop:resourceType ?resourceType .
%record aoprop:nativeSubject ?nativeSubject .
?nativeSubject aoprop:prefLabel ?nativeSubjectPrefLabel .
?nativeSubject aoprop:rdfAbout ?nativeSubject .
%record aoprop:derivedSubject ?derivedSubject .
?derivedSubject aoprop:prefLabel ?derivedSubjectPrefLabel .
?derivedSubject aoprop:source "Getty AAT" .
%record aoprop:aatSubjects ?derivedSubject .
?derivedSubject aoprop:id ?derivedSubject .
?derivedSubject aoprop:label ?derivedSubjectPrefLabel .
?derivedSubject aoprop:lang ?aatSubjectsLang .
%record aoprop:title ?title .
%record aoprop:description ?description .
%record aoprop:language ?language .
}
from <https://ariadne-infrastructure.eu/api_________::ariadne_plus::%datasource::aat>
from <https://ariadne-infrastructure.eu/ariadneplus::%datasource::aatplus>
from <https://ariadne-infrastructure.eu/ariadneplus::%datasource::periodo>
from <https://ariadne-infrastructure.eu/ariadneplus::%datasource::periodoplus>
from <https://ariadne-infrastructure.eu/api_________::ariadne_plus::%datasource::%collectionId>
where {
%record aocat:has_language / skos:prefLabel ?language .
%record aocat:has_original_id ?originalId .
%record aocat:has_creator ?creator .
?creator aocat:has_name ?creatorName .
%record aocat:has_title ?title .
%record aocat:has_type / skos:prefLabel ?resourceType .
optional {
?creator aocat:has_email ?creatorEmail .
}
optional {
%record aocat:has_description ?description .
}
optional {
%record aocat:has_access_policy / rdfs:label ?accessPolicy .
}
optional {
%record aocat:has_landing_page / rdfs:label ?landingPage .
}
{
select *
where {
%record aocat:was_issued ?issued .
%record aocat:was_modified ?modified .
%record aocat:has_contributor ?contributor .
?contributor aocat:has_name ?contributorName .
%record aocat:has_responsible ?legalResponsible .
?legalResponsible aocat:has_name ?legalResponsibleName .
%record aocat:has_owner ?owner .
?owner aocat:has_name ?ownerName .
%record aocat:has_publisher ?publisher .
?publisher aocat:has_name ?publisherName .
%record aocat:has_access_rights ?accessRights .
%record aocat:has_ARIADNE_subject ?archeologicalResourceType .
?archeologicalResourceType skos:prefLabel ?archeologicalResourceTypeName .
optional {
?contributor aocat:has_email ?contributorEmail .
}
optional {
?legalResponsible aocat:has_email ?legalResponsibleEmail .
}
optional {
?owner aocat:has_email ?ownerEmail .
}
optional {
?publisher aocat:has_email ?publisherEmail .
}
}
}
BIND (lang(?derivedSubjectPrefLabel) as ?aatSubjectsLang)
}