Skip to content

Commit

Permalink
#52 - Implement feature extractors from GESIS paper
Browse files Browse the repository at this point in the history
- refactored create query part
  • Loading branch information
maxxkia committed Sep 19, 2017
1 parent 85cab6c commit a4034e4
Showing 1 changed file with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,55 @@ public TheSozResource(String theSozPath)
@Override
public boolean containsConceptLabel(String conceptLabel)
{
Query query;
try {
query = QueryFactory
.create(prefixString
+ "SELECT ?term WHERE { "
+ " ?term ?p ?label . "
+ " FILTER ((?p IN (skos:prefLabel, skos:altLabel)) "
+ " && str(?label) = \"" + conceptLabel + "\") }");
Query query = createSelectQuery(conceptLabel);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();

return results.hasNext();
}
catch (QueryException ex) {
//TODO log
// TODO log
System.err.println("Cannot parse query for conceptLabel=[" + conceptLabel + "]");
return false;
}
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();

return results.hasNext();
}
}

@Override
public boolean containsConceptLabel(String conceptLabel, String language)
{
Query query = QueryFactory
boolean result = false;
try {
Query query = createSelectQuery(conceptLabel);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();

while (results.hasNext()) {
QuerySolution solution = results.next();
Literal literal = solution.getLiteral("?label");
if (literal.getLanguage() != null && language.equals(literal.getLanguage())) {
result = true;
break;
}
}
}
catch (QueryException ex) {
// TODO log
System.err.println("Cannot parse query for conceptLabel=[" + conceptLabel + "]");
}
return result;
}

private Query createSelectQuery(String conceptLabel)
throws QueryException
{
Query query;
query = QueryFactory
.create(prefixString
+ "SELECT ?label WHERE { "
+ " ?term ?p ?label . "
+ " FILTER ((?p IN (skos:prefLabel, skos:altLabel)) "
+ " && str(?label) = \"" + conceptLabel + "\") }");
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();

while (results.hasNext()) {
QuerySolution solution = results.next();
Literal literal = solution.getLiteral("?label");
if (literal.getLanguage() != null && language.equals(literal.getLanguage())) {
return true;
}
}
return false;
return query;
}
}

0 comments on commit a4034e4

Please sign in to comment.