protected static final String QUERY_PROLOG = StrUtils.strjoinNL( "prefix : ", "prefix rdfs: ", "prefix bdr: ", "prefix apf: " ); 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; }