private Block handleRootPath(Path<?> path, Filters filters) { MappedClass mappedClass = configuration.getMappedClass(path.getType()); UID rdfType = mappedClass.getUID(); UID context = mappedClass.getContext(); QID pathNode = new QID(path.toString()); pathToMapped.put(path, pathNode); if (rdfType != null) { Collection<UID> types = ontology.getSubtypes(rdfType); if (types.size() > 1 && inferenceOptions.subClassOf()) { QID type = new QID(path + "_type"); filters.add(type.in(types)); return Blocks.pattern(pathNode, RDF.type, type); } else { if (context != null) { pathToContext.put(path, context); return Blocks.pattern(pathNode, RDF.type, rdfType, context); } else { return Blocks.pattern(pathNode, RDF.type, rdfType); } } } else { throw new IllegalArgumentException("No types mapped against " + path.getType().getName()); } }
private Collection<NODE> convertList(ID subject, UID context) { List<NODE> list = new ArrayList<NODE>(); while (subject != null && !subject.equals(RDF.nil)) { if (logger.isDebugEnabled()) { logger.debug("query for list elements of " + subject); } Map<String, NODE> nodes = listCache.get(subject); if (nodes == null) { nodes = new RDFQueryImpl(connection) .where(Blocks.S_REST, Blocks.optional(Blocks.S_FIRST)) .set(QNODE.s, subject) .selectSingle(QNODE.first, QNODE.rest); } if (nodes == null) { if (list.size() == 0) { list.add(subject); } break; } NODE value = nodes.get(QNODE.first.getName()); if (value != null) { list.add(value); } else { list.add(null); } subject = (ID) nodes.get(QNODE.rest.getName()); } return list; }
@Test public void Complex() { QID u = new QID("u"), u2 = new QID("u2"); QLIT label = new QLIT("label"); UID User = new UID(TEST.NS, "User"); ID id = new BID(), id2 = new BID(), id3 = new BID(); connection().update(null, Arrays.asList( new STMT(id, RDF.type, User), new STMT(id2, RDF.type, User), new STMT(id3, RDF.type, User), new STMT(id, RDFS.label, new LIT("x")), new STMT(id2, RDFS.label, new LIT("x")), new STMT(id3, RDFS.label, new LIT("y")))); CloseableIterator<Map<String, NODE>> iterator = query().where( Blocks.pattern(u, RDF.type, User), Blocks.pattern(u2, RDF.type, User), Blocks.pattern(u2, RDFS.label, label), Blocks.pattern(u, RDFS.label, label), u.ne(u2) ).select(u, u2); List<Map<String, NODE>> list = IteratorAdapter.asList(iterator); assertEquals(2, list.size()); }
public QID id() { if (id == null) { id = new QID(getName()); } return id; }
query.where(QNODE.s.in(ids)); CloseableIterator<STMT> stmts = query.construct(Blocks.SPOC); Map<ID, Multimap<UID, STMT>> directProps = getPropertiesMap(stmts, false);
@Test public void Pattern_via_a() { assertEquals( Blocks.pattern(subject, RDF.type, RDFS.Class), subject.a(RDFS.Class)); }
@Test public void Pattern_via_has_with_Context() { assertEquals( Blocks.pattern(subject, predicate, object, context), subject.has(predicate, object, context)); }
@Test public void Pattern_via_is() { assertEquals( Blocks.pattern(object, predicate, subject), subject.is(predicate, object)); }
@Test public void NotIn() { assertEquals( "!{s} in [http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/1999/02/22-rdf-syntax-ns#text]", QNODE.s.notIn(RDF.type, RDF.text).toString()); }
public com.mysema.rdfbean.model.QID _id() { if (id == null) id = new com.mysema.rdfbean.model.QID(PathMetadata.forProperty(this,"id")); return id; }
@Test(expected = IllegalArgumentException.class) @Ignore public void In_Empty_Is_Not_Allowed() { QNODE.s.in(); }
@Test public void Pattern_via_a_with_Context() { assertEquals( Blocks.pattern(subject, RDF.type, RDFS.Class, context), subject.a(RDFS.Class, context)); }
@Test public void Pattern_via_has() { assertEquals( Blocks.pattern(subject, predicate, object), subject.has(predicate, object)); }
query.where(QNODE.s.in(ids));
@Test public void ToString() { MiniConnection connection = new MiniRepository().openConnection(); RDFQuery query = new RDFQueryImpl(connection); query.where(QNODE.s.a(RDFS.Resource)); assertEquals( "SELECT * WHERE { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> } ", query.toString().replaceAll("\\s+", " ")); }
@Test public void Optional_via_has() { assertEquals( Blocks.optional(Blocks.pattern(subject, predicate, object)), subject.has(predicate, object).asOptional()); }