/** * Run a datatype range check on all literal values of all properties with a range declaration. * @param report */ protected void performDatatypeRangeValidation(StandardValidityReport report) { HashMap<Node, List<RDFDatatype>> dtRange = getDTRange(); for ( Node prop : dtRange.keySet() ) { for ( Iterator<Triple> i = find( null, prop, null ); i.hasNext(); ) { Triple triple = i.next(); report.add( checkLiteral( prop, triple ) ); } } }
/** * Run a datatype range check on all literal values of all properties with a range declaration. * @param report */ protected void performDatatypeRangeValidation(StandardValidityReport report) { HashMap<Node, List<RDFDatatype>> dtRange = getDTRange(); for ( Node prop : dtRange.keySet() ) { for ( Iterator<Triple> i = find( null, prop, null ); i.hasNext(); ) { Triple triple = i.next(); report.add( checkLiteral( prop, triple ) ); } } }
/** * Return a map from property nodes to a list of RDFDatatype objects * which have been declared as the range of that property. */ protected HashMap<Node, List<RDFDatatype>> getDTRange() { if (dtRange == null) { dtRange = new HashMap<>(); for (Iterator<Triple> i = find(null, RDFS.range.asNode(), null); i.hasNext(); ) { Triple triple = i.next(); Node prop = triple.getSubject(); Node rangeValue = triple.getObject(); if (rangeValue.isURI()) { RDFDatatype dt = TypeMapper.getInstance().getTypeByName(rangeValue.getURI()); if (dt != null) { List<RDFDatatype> range = dtRange.get(prop); if (range == null) { range = new ArrayList<>(); dtRange.put(prop, range); } range.add(dt); } } } } return dtRange; }
/** * Return a map from property nodes to a list of RDFDatatype objects * which have been declared as the range of that property. */ protected HashMap<Node, List<RDFDatatype>> getDTRange() { if (dtRange == null) { dtRange = new HashMap<>(); for (Iterator<Triple> i = find(null, RDFS.range.asNode(), null); i.hasNext(); ) { Triple triple = i.next(); Node prop = triple.getSubject(); Node rangeValue = triple.getObject(); if (rangeValue.isURI()) { RDFDatatype dt = TypeMapper.getInstance().getTypeByName(rangeValue.getURI()); if (dt != null) { List<RDFDatatype> range = dtRange.get(prop); if (range == null) { range = new ArrayList<>(); dtRange.put(prop, range); } range.add(dt); } } } } return dtRange; }
@Test public void testTabledGoalsLeak() throws Exception { Graph data = Factory.createGraphMem(); data.add(new Triple(a, ty, C1)); List<Rule> rules = Rule .parseRules("[r1: (?x p ?t) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]" + "[r2: (?t rdf:type C2) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]"); FBRuleInfGraph infgraph = (FBRuleInfGraph) createReasoner(rules).bind( data); LPBRuleEngine engine = getEngineForGraph(infgraph); assertEquals(0, engine.activeInterpreters.size()); assertEquals(0, engine.tabledGoals.size()); ExtendedIterator<Triple> it = infgraph.find(a, ty, C1); it.close(); // how many were cached assertEquals(1, engine.tabledGoals.size()); // and no leaks of activeInterpreters assertEquals(0, engine.activeInterpreters.size()); // Now ask again: it = infgraph.find(a, ty, C1); it.close(); // if it was a cache hit, no change here: assertEquals(1, engine.tabledGoals.size()); assertEquals(0, engine.activeInterpreters.size()); //the cached generator should not have any consumingCP left for(Generator generator : engine.tabledGoals.asMap().values()){ assertEquals(0, generator.consumingCPs.size()); } }
@Test public void testTabledGoalsLeak() throws Exception { Graph data = Factory.createGraphMem(); data.add(new Triple(a, ty, C1)); List<Rule> rules = Rule .parseRules("[r1: (?x p ?t) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]" + "[r2: (?t rdf:type C2) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]"); FBRuleInfGraph infgraph = (FBRuleInfGraph) createReasoner(rules).bind( data); LPBRuleEngine engine = getEngineForGraph(infgraph); assertEquals(0, engine.activeInterpreters.size()); assertEquals(0, engine.tabledGoals.size()); ExtendedIterator<Triple> it = infgraph.find(a, ty, C1); it.close(); // how many were cached assertEquals(1, engine.tabledGoals.size()); // and no leaks of activeInterpreters assertEquals(0, engine.activeInterpreters.size()); // Now ask again: it = infgraph.find(a, ty, C1); it.close(); // if it was a cache hit, no change here: assertEquals(1, engine.tabledGoals.size()); assertEquals(0, engine.activeInterpreters.size()); //the cached generator should not have any consumingCP left for(Generator generator : engine.tabledGoals.asMap().values()){ assertEquals(0, generator.consumingCPs.size()); } }
ExtendedIterator<Triple> it = infgraph.find(test, ty, C2); assertFalse(it.hasNext()); it.close();
ExtendedIterator<Triple> it = infgraph.find(test, ty, C2); assertFalse(it.hasNext()); it.close();
assertTrue("Forward rule count", infgraph.getNRulesFired() == 3); TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), new Object[] { new Triple(a, p, a), new Triple(a, p, b),
assertTrue("Forward rule count", infgraph.getNRulesFired() == 3); TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), new Object[] { new Triple(a, p, a), new Triple(a, p, b),