org.apache.jena.graph.Triple.subjectMatches()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.apache.jena.graph.Triple.subjectMatches()方法的一些代码示例,展示了Triple.subjectMatches()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Triple.subjectMatches()方法的具体详情如下:
包路径:org.apache.jena.graph.Triple
类名称:Triple
方法名:subjectMatches

Triple.subjectMatches介绍

暂无

代码示例

代码示例来源:origin: SmartDataAnalytics/DL-Learner

/**
 * Returns all triple patterns in given SPARQL query that have the given node in subject position, i.e. the outgoing
 * triple patterns.
 * @param query The SPARQL query.
 * @param node the node
 * @return
 */
public Set<Triple> extractOutgoingTriplePatterns(Query query, Node node){
  return extractTriplePattern(query, false).stream()
      .filter(t -> t.subjectMatches(node))
      .collect(Collectors.toSet());
}

代码示例来源:origin: dice-group/NLIWOD

/**
 * Returns all triple patterns in given SPARQL query that have the given
 * node in subject position, i.e. the outgoing triple patterns.
 * 
 * @param query The SPARQL query.
 */
public Set<Triple> extractOutgoingTriplePatterns(final Query query, final Node node) {
  Set<Triple> triplePatterns = extractTriplePattern(query, false);
  // remove triple patterns not containing triple patterns with given node
  // in subject position
  for (Iterator<Triple> iterator = triplePatterns.iterator(); iterator.hasNext();) {
    Triple triple = iterator.next();
    if (!triple.subjectMatches(node)) {
      iterator.remove();
    }
  }
  return triplePatterns;
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

/**
 * Check if there is an RDF-path from source to target.
 *
 * @param source  the source node
 * @param target  the target node
 * @param triples the set of triples in the graph
 * @return whether both nodes are RDF-connected by the given set of triples, i.e. if there is an RDF-path from
 * source to target.
 */
public static boolean isRDFConnected(Node source, Node target, Set<Triple> triples) {
  // trivial case: node is always RDF-connected to itself
  if(source.equals(target)) {
    return true;
  }
  
  // other case: 
  for (Triple t : triples) {
    if(t.subjectMatches(source) && 
        (isRDFConnected(t.getPredicate(), target, triples) ||
         isRDFConnected(t.getObject(), target, triples))
        ) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

@Override
        public int compare(Triple o1, Triple o2) {
          boolean same = o1.subjectMatches(o2.getSubject())
              && o2.predicateMatches(o2.getPredicate())
              && o1.getObject().isVariable() && o2.getObject().isVariable();
//                            && !var2OutgoingTPs.containsKey(o1.getObject());
          if (same) return 0;
          return comp.compare(o1, o2);
        }
      });

代码示例来源:origin: SmartDataAnalytics/DL-Learner

@Override
        public int compare(Triple o1, Triple o2) {
          boolean same = o1.subjectMatches(o2.getSubject())
              && o2.predicateMatches(o2.getPredicate())
              && o1.getObject().isVariable() && o2.getObject().isVariable();
//                            && !var2IncomingTPs.containsKey(o1.getObject());
          if (same) return 0;
          return comp.compare(o1, o2);
        }
      });

代码示例来源:origin: apache/jena

public void testElementMatches()
  {
  assertTrue( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "S" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "P" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "O" ) ) );
/* */
  assertFalse( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "Z" ) ) );
  assertFalse( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "Q" ) ) );
  assertFalse( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "I" ) ) );        
/* */
  assertTrue( NodeCreateUtils.createTriple( "?? P O" ).subjectMatches( node( "SUB" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S ?? O" ).predicateMatches( node( "PRED" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S P ??" ).objectMatches( node( "OBJ" ) ) );    
  }

代码示例来源:origin: org.apache.jena/jena-core

public void testElementMatches()
  {
  assertTrue( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "S" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "P" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "O" ) ) );
/* */
  assertFalse( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "Z" ) ) );
  assertFalse( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "Q" ) ) );
  assertFalse( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "I" ) ) );        
/* */
  assertTrue( NodeCreateUtils.createTriple( "?? P O" ).subjectMatches( node( "SUB" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S ?? O" ).predicateMatches( node( "PRED" ) ) );
  assertTrue( NodeCreateUtils.createTriple( "S P ??" ).objectMatches( node( "OBJ" ) ) );    
  }

相关文章