У меня проблема с моим Java-приложением.
Я пытаюсь обработать запросы на сервере Fuseki, чтобы получить ответ от загруженной на него онтологии.
На мой пятый запрос сервер блокируется и не возвращает никакого ответа, и иногда я получаю эту ошибку
AVERTISSEMENT: The web application [MiCorr-WebServices] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation. Stack trace of request processing thread:[
sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
Я попытался инвертировать запросы, чтобы увидеть, не связана ли проблема с запросом, но результаты те же.
Кто-нибудь может мне помочь найти решение этой проблемы. Вы можете увидеть мои классы Java, которые я использую для запроса сервера fuseki. Я не совсем уверен в этом, но я получаю хорошие результаты по 4 первым запросам.
public class OntologyService {
private Artefacts artefacts;
private List<QuerySolution> querySolutionList;
private RDFConnectionRemoteBuilder builder;
private OntologyQuery query;
public OntologyService() {
// - Création de la connexion sur le serveur Fuseki
builder = RDFConnectionFuseki.create().destination("http://localhost:8080/MiCorrDS/")
.gspEndpoint("MiCorrGraph");
RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build();
query = new OntologyQuery(conn);
artefacts = new Artefacts();
}
public Artefacts getResearchProperties(String text, String country, String metalFamily, String corrosionForms,
String environments) {
querySolutionList = new ArrayList<>();
// - Recherche si le texte saisi existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(text);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setText(artefact.getLiteral("?artefactName").getString());
artefacts.setTextId(artefact.getLiteral("?artefactId").getInt());
artefacts.setTextType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setText("");
artefacts.setTextId(0);
artefacts.setTextType("");
}
// - Recherche si le pays saisi existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(country);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setCountry(artefact.getLiteral("?artefactName").getString());
artefacts.setCountryId(artefact.getLiteral("?artefactId").getInt());
artefacts.setCountryType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setCountry("");
artefacts.setCountryId(0);
artefacts.setCountryType("");
}
// - Recherche si le famille du métal saisie existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(metalFamily);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setMetalFamily(artefact.getLiteral("?artefactName").getString());
artefacts.setMetalFamilyId(artefact.getLiteral("?artefactId").getInt());
artefacts.setMetalFamilyType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setMetalFamily("");
artefacts.setMetalFamilyId(0);
artefacts.setMetalFamilyType("");
}
// - Recherche si la forme de corrosion saisie existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(corrosionForms);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setCorrosionForms(artefact.getLiteral("?artefactName").getString());
artefacts.setCorrosionFormsId(artefact.getLiteral("?artefactId").getInt());
artefacts.setCorrosionFormsType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setCorrosionForms("");
artefacts.setCorrosionFormsId(0);
artefacts.setCorrosionFormsType("");
}
// - Recherche si l'environnement saisi existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(environments);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setEnvironments(artefact.getLiteral("?artefactName").getString());
artefacts.setEnvironmentsId(artefact.getLiteral("?artefactId").getInt());
artefacts.setEnvironmentsType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setEnvironments("");
artefacts.setEnvironmentsId(0);
artefacts.setEnvironmentsType("");
}
// - Recherche si le famille du métal saisie existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(corrosionForms);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setCorrosionForms(artefact.getLiteral("?artefactName").getString());
artefacts.setCorrosionFormsId(artefact.getLiteral("?artefactId").getInt());
artefacts.setCorrosionFormsType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setCorrosionForms("");
artefacts.setCorrosionFormsId(0);
artefacts.setCorrosionFormsType("");
}
return artefacts;
}
}
И класс запроса
public class OntologyQuery {
private static final String FILENAME1 = "C:\\DEV\\SPARQL\\micorr_query1.txt";
private static final boolean CONSOLE_LOG = true;
private RDFConnectionFuseki conn;
public OntologyQuery(RDFConnectionFuseki remoteConn) {
conn = remoteConn;
}
public List<QuerySolution> getPropertiesDataQuery(String text) {
String sparqlRequest = readFileToString(FILENAME1);
sparqlRequest = sparqlRequest.replaceAll("%text%", text);
System.out.println(sparqlRequest);
Query query = QueryFactory.create(sparqlRequest);
List<QuerySolution> list = null;
// In this variation, a connection is built each time.
if (CONSOLE_LOG) {
conn.queryResultSet(query, ResultSetFormatter::out);
}
list = ResultSetFormatter.toList(conn.query(query).execSelect());
return list;
}
private static String readFileToString(String filename) {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
sb.append(sCurrentLine);
sb.append(" ");
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
}
А вот и запрос SPARQL
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl:<http://www.w3.org/2002/07/owl#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX vocab:<http://micorr.ig.he-arc.ch/vocab#>
PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?artefact ?artefactId ?artefactType ?artefactName
FROM <http://localhost:8080/MiCorrDS/data/MiCorrGraph>
WHERE {
?artefact a ?artefactType .
?artefact rdfs:label "%text%" .
BIND(IRI(CONCAT(STR(?artefactType), "_id")) AS ?iriConcat)
BIND("%text%" AS ?artefactName)
?artefact ?iriConcat ?artefactId .
FILTER( STRSTARTS(str(?artefactType), "http://micorr.ig.he-arc.ch/vocab") )
}
Спасибо за вашу помощь.
Версия fuseki - 3.6.0, и я использую Tomcat 9. Это первая версия моего Java-приложения, поэтому, если лучше использовать RDFConnectionRemote
, я попробую.
FROM <...>
- Если вы хотите получить доступ к этому графику с помощью запроса, то GRAPH <>
- лучший способ. WHERE { GRAPH <...> { ?artefact ... } }
.
Я меняю свой запрос, но в моем приложении ничего не меняется. У меня всегда одна и та же проблема
Какая версия Фусеки? А вы используете Tomcat? Вы пробовали использовать
RDFConnectionRemote
, поскольку ваше использование не является специфичным для Fuseki. Кажется, что ничего плохого нет - если у вас есть пример, относящийся к возникшей проблеме (без операций, связанных с приложением), это было бы полезно. stackoverflow.com/help/mcve