openrdf芝麻模型中的多重过滤器

时间:2016-01-15 21:23:55

标签: java filter rdf sesame triples

我想过滤一个Model,得到所有具有特定谓词和C类主题的三元组。下面的代码不会返回任何结果,是否有人知道如何实现它?

return triples.filter(null,  new URIImpl(property.getFullIRI()), null).filter
(null, RDF.TYPE,new URIImpl(C.getFullIRI()));

1 个答案:

答案 0 :(得分:1)

问题是您在第一个结果上应用第二个 beforeEach(angular.mock.inject(($compile: ng.ICompileService, $rootScope: any, $controller: any, $state: ng.ui.IStateService, jwtHelper: angular.jwt.IJwtHelper) => { controllerScope = $rootScope.$new(); navbarController = $controller('NavbarController', { $scope: controllerScope }); currentDate = new Date(); rootScope = $rootScope; state = $state; jwt = jwtHelper; } it('should get broadcast for user token', () => { spyOn(controllerScope, '$on'); spyOn(jwt, 'decodeToken'); //state.go('home'); Was trying a different way to trigger the event rootScope.$broadcast('$stateChangeStart', [{ toState: 'home' }]); expect(controllerScope.$on).toHaveBeenCalled(); expect(jwt.decodeToken).toHaveBeenCalled(); }); - 但第一个过滤器的结果包含三元组,其中包含您过滤的属性 - 所以第二个过滤器永远不会返回任何空结果(因为中间结果中没有三元组会有filter谓词)。

由于您以这种方式表达“非顺序”的辅助约束,因此您无法仅通过过滤来解决此问题。您需要构建一个新的rdf:type并随时填写数据。这些方面的东西:

Model

以上适用于Sesame 2.如果您使用的是Sesame 4(支持Java 8及其Stream API),您可以更轻松地执行此操作,如下所示:

 // always use a ValueFactory, avoid instantiating URIImpl directly.
 ValueFactory vf = ValueFactoryImpl().getInstance(); 
 URI c = vf.createURI(C.getFullIRI());
 URI prop = vf.createURI(property.getFullIRI())

 // create a new Model for the resulting triple collection
 Model result = new LinkedHashModel();

 // filter on the supplied property
 Model propMatches = triples.filter(null, prop, null);
 for(Resource subject: propMatches.subjects()) {

    // check if the selected subject is of the supplied type
    if (triples.contains(subject, RDF.TYPE, c)) {
          // add the type triple to the result
          result.add(subject, RDF.TYPE, c);

          // add the property triple(s) to the result 
          result.addAll(propMatches.filter(subject, null, null));
    }
 }
 return result;