Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected static final String QUERY_PROLOG =
- StrUtils.strjoinNL(
- "prefix : <http://purl.bdrc.io/ontology/core/>",
- "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>",
- "prefix bdr: <http://purl.bdrc.io/resource/>",
- "prefix apf: <http://jena.apache.org/ARQ/property#>"
- );
- protected static final String PERSON_DOUBLE_QUERY = StrUtils.strjoinNL(
- QUERY_PROLOG,
- "select ?diff",
- "where {",
- " {",
- " select (count(?id) as ?c) (count(distinct ?id) as ?cd)",
- " where {",
- " ?R :personName ?b .",
- " ?b rdfs:label ?nm .",
- " ?b a ?type .",
- " bind (lang(?nm) as ?lang) ",
- " ?id apf:concat(?type '+' ?nm '@' ?lang) .",
- " }",
- " } .",
- " bind (?c - ?cd as ?diff)",
- "}"
- );
- /*
- * return true if there are doubled triples in the model; otherwise, false
- * currently only tests DocType.PERSON and returns false otherwise
- */
- public static boolean resourceDoubled(String resource, Model m, DocType type) {
- if (type == DocType.PERSON) {
- ParameterizedSparqlString qStr = new ParameterizedSparqlString(PERSON_DOUBLE_QUERY);
- qStr.setIri("?R", resource);
- Query query = QueryFactory.create(qStr.asQuery());
- try (QueryExecution qexec = QueryExecutionFactory.create(query, m)) {
- ResultSet results = qexec.execSelect() ;
- if (results.hasNext()) {
- QuerySolution soln = results.nextSolution();
- Literal diffLit = soln.getLiteral("diff");
- int diff = diffLit.getInt();
- if (diff > 0) {
- return true;
- }
- }
- } catch (Exception ex) {
- TransferHelpers.logger.error("checkForDoubling failed: " + ex.getMessage(), ex);
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement