It's definitely possible to do queries like that with SPARQL property paths, a la ?resource rdf:type ?class . foaf:Document rdfs:subClass* ?class . You would need to put your ontology into the dataset along with your data. Andy did a good presentation a few years ago introducing new features in SPARQL 1.1 where he made this point-- that property paths are a way of permitting the client to control inference. I think it's on-line somewhere but I can't put my finger on it right now.
I'm not arguing that this is better in all circumstances, just that it's a useful alternative (e.g. if you are working remotely from the data and querying it via SPARQL, that sort of situation). You can do something similar programmatically "manually" (by tracing rdfs:subClass out), but again, I'm not suggesting that so doing is necessarily any better performance-wise. Another question: what are the resources you are avoiding/filtering? IOW, what would be the resources that would be instances of some class of interest but _don't_ actually exist in the original model? Would they necessarily be bnodes? Just trying to guess at what might be the strongest way to arrange the basic "get some candidates and then filter them" approach. ajs6f > On Dec 2, 2017, at 12:37 PM, Martynas Jusevičius <[email protected]> > wrote: > > Possible that there are multiple matches, but unlikely :) In that case I > just need any one of them. > > InfModel is only used for this case. I don't see how I can avoid it. If say > I want to find an instance of foaf:Document or its subclasses, just looking > at the raw model such as > > :instance a my:Class . > > is not enough, because it doesn't know whether my:Class is a subclass of > foaf:Document or not, without adding schema. That is why I'm using InfModel. > > On Sat, Dec 2, 2017 at 6:31 PM, ajs6f <[email protected]> wrote: > >> Is it possible in your use case that there is more than one of these guys, >> or do you have reason to assume that if there is one, it is unique? If >> there is more than one, do you need to produce all examples? Is this the >> only use of the inference model (IOW could you do the inference in a >> different way) or do you need other inference facilities and therefore the >> InfModel is really required? >> >> ajs6f >> >>> On Dec 2, 2017, at 12:27 PM, Martynas Jusevičius <[email protected]> >> wrote: >>> >>> Hi, >>> >>> what would be the most effective way to find a Resource that >>> - belongs to a raw Model >>> - in an instance of class X in an InfModel (which is based on the Model >>> above) >>> ? >>> >>> I came up with something which iterates instances and filters by >> membership >>> (lambda syntax not tested): >>> >>> infModel.listSubjectsWithProperty(RDF.type, class). >>> filterKeep(r -> infModel.getRawModel().containsResource(r)) >>> >>> If a lot of instances were inferred in the InfModel, I can see this being >>> slow. >>> >>> Is there a better way? Maybe inversing the iterations somehow? >>> >>> >>> Martynas >> >>
