com.hp.hpl.jena.rdf.model.Model.isIsomorphicWith()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(109)

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

Model.isIsomorphicWith介绍

[英]Compare this Model with another for equality ignoring the labels on bNodes. See RDF Concepts.

Two models are isomorphic when each statement in one can be matched with a statement in the other. Statements which are identical match.

Special treatment is given to anonymous nodes. A binding is a one to one mapping which maps each anonymous node in this model to an anonymous node in model. Two statements s1 and s2 match under a binding if if s1.subject is anonymous and s2.subject is anonymous and the binding maps s1.subject to s2.subject.

Two models are isomorphic if there is a binding that allows all the statements in one model to match a a statement in the other.
[中]将此模型与另一个模型进行比较,以便忽略B节点上的标签。见RDF Concepts
当一个模型中的每个语句可以与另一个模型中的语句匹配时,两个模型是同构的。相同的语句匹配。
对匿名节点进行特殊处理。绑定是一种一对一的映射,它将this模型中的每个匿名节点映射到model模型中的一个匿名节点。两条语句s1和s2在绑定s1下匹配。主题为匿名和s2。主题是匿名的,绑定映射为s1。以s2为准。主题
如果存在允许一个模型中的所有语句与另一个模型中的语句匹配的绑定,则两个模型是同构的。

代码示例

代码示例来源:origin: fr.inria.eventcloud/eventcloud-api

/**
 * {@inheritDoc}
 */
@Override
public boolean isIsomorphicWith(Model g) {
  return super.object.isIsomorphicWith(g);
}

代码示例来源:origin: bio2rdf/bio2rdf-scripts

public boolean isIsomorphicWith(Model g) {
  return model.isIsomorphicWith(g);
}

代码示例来源:origin: com.hp.hpl.jena/arq

/** Compare two result sets for bNode isomorphism equivalence.
 * Only does RDF term comparison.
 */ 
public static boolean isomorphic(ResultSet rs1, ResultSet rs2)
{
  Model m1 = ResultSetFormatter.toModel(rs1) ;
  Model m2 = ResultSetFormatter.toModel(rs2) ;
  return m1.isIsomorphicWith(m2) ;
}

代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq

/** Compare two result sets for bNode isomorphism equivalence.
 * Only does RDF term comparison.
 */ 
public static boolean isomorphic(ResultSet rs1, ResultSet rs2)
{
  Model m1 = ResultSetFormatter.toModel(rs1) ;
  Model m2 = ResultSetFormatter.toModel(rs2) ;
  return m1.isIsomorphicWith(m2) ;
}

代码示例来源:origin: org.semweb4j/rdf2go.impl.jena

@Override
public boolean isIsomorphicWith(Model other) {
  if(other instanceof ModelImplJena) {
    return this.jenaModel.isIsomorphicWith(((ModelImplJena)other).getInternalJenaModel());
  } else {
    // TODO: reasoning might be different
    ModelImplJena otherJenaModel = new ModelImplJena(Reasoning.none);
    otherJenaModel.addAll(other.iterator());
    return this.jenaModel.isIsomorphicWith(otherJenaModel.getInternalJenaModel());
  }
}

代码示例来源:origin: epimorphics/elda

public boolean checkModel(Model actual, String expectedFile) {
  Model expected = EldaFileManager.get().loadModel(expectedFile);
  if ( ! expected.isIsomorphicWith(actual)) {
    System.out.println("Model check failed, found:");
    actual.write(System.out, "Turtle");
    return false;
  } else {
    return true;
  }
}

代码示例来源:origin: epimorphics/elda

@Test public void testConfigLoader() {
    Model m = ConfigLoader.loadModelExpanding("includefiles/toplevel.ttl");		
    assertTrue(m.isIsomorphicWith(testModel));
  }
}

代码示例来源:origin: com.github.jsonld-java/jsonld-java-jena

private void rtRJRg(String filename) throws Exception {
    final Model model = loadModelFromClasspathResource("/com/github/jsonldjava/jena/"
        + filename);

    // Write a JSON-LD
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    RDFDataMgr.write(out, model, JSONLD);
    final ByteArrayInputStream r = new ByteArrayInputStream(out.toByteArray());

    // Read as JSON-LD
    final Model model2 = ModelFactory.createDefaultModel();
    RDFDataMgr.read(model2, r, null, JSONLD);

    assertFalse("JSON-LD model was empty", model2.isEmpty());

    // Compare
    if (!model.isIsomorphicWith(model2)) {
      System.out.println("## ---- DIFFERENT");
    }
  }
}

代码示例来源:origin: epimorphics/elda

@Test public void testModelEncode() {
    Model src = ModelIOUtils.modelFromTurtle(":r :p 42; :q :r2. :r2 :p 24 .");
    Context context = new Context();
    JsonObject obj = Encoder.get(context).encode(src);
    String encoding = obj.toString();
    Model dec = Decoder.decodeModel(context, new StringReader(encoding) );
    assertTrue( dec.isIsomorphicWith(src) );
  }
}

代码示例来源:origin: epimorphics/elda

@Test public void testIncludeReaderTriple() throws IOException {
  Model m = ModelFactory.createDefaultModel();
  Reader r = new IncludeReader("includefiles/toplevel.ttl");
  m.read(r, "", "TTL");
  r.close();
//
  Model expect = ModelFactory.createDefaultModel();
  Resource S = expect.createResource(ELDA_API.NS + "example");
  Property P = RDF.type;
  RDFNode O = XSD.xstring;
  expect.add(S, P, O);
//
  if (!m.isIsomorphicWith(expect)) fail("did not read concatenated turtle.");
  // System.err.println(">> OK.");
}

代码示例来源:origin: com.github.jsonld-java/jsonld-java-jena

private void graphJ2R(String inResource, String outResource) throws Exception {
  final Model model1 = loadModelFromClasspathResource("/com/github/jsonldjava/jena/"
      + inResource);
  assertFalse("Failed to load input model from classpath: " + inResource, model1.isEmpty());
  final Model model2 = loadModelFromClasspathResource("/com/github/jsonldjava/jena/"
      + outResource);
  assertFalse("Failed to load output model from classpath: " + outResource, model2.isEmpty());
  assertTrue("Input graph " + inResource + " not isomorphic to output dataset" + outResource,
      model1.isIsomorphicWith(model2));
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void query1()
{
  Dataset ds = create() ;
  Model m = ds.getDefaultModel() ;
  load1(m) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE {?s ?p ?o}" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: net.sf.taverna.t2.activities/sadi-activity

/**
 * Test method for
 * {@link net.sf.taverna.t2.reference.sadi.RDFReference#setContents(java.lang.String)}
 * .
 */
@Test
public void testSetContents() {
  rdfReference.setContents("5");
  assertEquals("5", rdfReference.getContents());
  rdfReference.setContents(rdfURIResourceString);
  assertTrue(rdfReference.getContents().contains(
      "UniProt_Record rdf:about=\"http://purl.uniprot.org/uniprot/P12345\""));
  rdfReference.setContents(rdfResourceString);
  Model model1 = ModelFactory.createDefaultModel().read(new StringReader(rdfResourceString),
      null);
  Model model2 = ModelFactory.createDefaultModel().read(
      new StringReader(rdfReference.getContents()), null);
  assertTrue(model1.isIsomorphicWith(model2));
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void special1()
{
  Dataset ds = create() ;
  Model m = ds.getDefaultModel() ;
  load1(m) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE { GRAPH <"+defaultGraph+"> {?s ?p ?o}}" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void special2()
{
  Dataset ds = create() ;
  load1(ds.getDefaultModel()) ;
  load2(ds.getNamedModel("http://example/graph1")) ;
  load3(ds.getNamedModel("http://example/graph2")) ;
  
  Model m = ModelFactory.createDefaultModel() ;
  load2(m) ;
  load3(m) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE { GRAPH <"+unionGraph+"> {?s ?p ?o}}" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void generalDataset3()
{
  Dataset ds = create() ;
  load1(ds.getDefaultModel()) ;
  load2(ds.getNamedModel("http://example/graph1")) ;
  load3(ds.getNamedModel("http://example/graph2")) ;
  Model m = ds.getDefaultModel() ;
  
  // Use the default model in one dataset as a named model in another.
  DataSource ds2 = DatasetFactory.create() ;
  ds2.addNamedModel("http://example/graphOther", m) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE { {?s ?p ?o} UNION { GRAPH <http://example/graphOther> {?s ?p ?o} } }" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void generalDataset2()
{
  Dataset ds = create() ;
  load1(ds.getDefaultModel()) ;
  load2(ds.getNamedModel("http://example/graph1")) ;
  load3(ds.getNamedModel("http://example/graph2")) ;
  Model m = ds.getNamedModel("http://example/graph2") ;
  
  // Use graph1 as a differently named model.
  DataSource ds2 = DatasetFactory.create() ;
  ds2.addNamedModel("http://example/graphOther", m) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE { {?s ?p ?o} UNION { GRAPH <http://example/graphOther> {?s ?p ?o} } }" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void generalDataset1()
{
  Dataset ds = create() ;
  load1(ds.getDefaultModel()) ;
  load2(ds.getNamedModel("http://example/graph1")) ;
  load3(ds.getNamedModel("http://example/graph2")) ;
  Model m = ds.getNamedModel("http://example/graph2") ;
  
  // Use graph2 as default model.
  DataSource ds2 = DatasetFactory.create() ;
  ds2.setDefaultModel(ds.getNamedModel("http://example/graph2")) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE { ?s ?p ?o}" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: com.hp.hpl.jena/tdb

@Test public void special3()
{
  Dataset ds = create() ;
  load1(ds.getDefaultModel()) ;
  load2(ds.getNamedModel("http://example/graph1")) ;
  load3(ds.getNamedModel("http://example/graph2")) ;
  
  Model m = ModelFactory.createDefaultModel() ;
  load2(m) ;
  load3(m) ;
  
  String qs = "CONSTRUCT {?s ?p ?o } WHERE { ?s ?p ?o }" ;
  Query q = QueryFactory.create(qs) ;
  QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
  qExec.getContext().set(TDB.symUnionDefaultGraph, true) ;
  Model m2 = qExec.execConstruct() ;
  assertTrue(m.isIsomorphicWith(m2)) ;
}

代码示例来源:origin: com.hp.hpl.jena/sdb

@Test public void model_4()
{
  Model assem = FileManager.get().loadModel(dir+"graph-assembler.ttl") ;
  Resource xDft = assem.getResource("http://example/test#graphDft") ;
  Resource xNamed = assem.getResource("http://example/test#graphNamed") ;
  
  Store store = create(assem) ;
  
  Model model1 = (Model)Assembler.general.open(xDft) ;
  Model model2 = (Model)Assembler.general.open(xNamed) ;
  // Check they are not connected to the same place in the store 
  Resource s = model1.createResource() ;
  Property p = model1.createProperty("http://example/p") ;
  Literal o = model1.createLiteral("foo") ;
  
  model1.add(s,p,o) ;
  assertTrue(model1.contains(s, p, o)) ;
  
  assertTrue(model1.size() == 1 ) ;
  assertTrue(model2.size() == 0 ) ;
  
  assertFalse(model1.isIsomorphicWith(model2)) ;
}

相关文章

Model类方法