Package com.complexible.common.openrdf.model

Examples of com.complexible.common.openrdf.model.ExtGraph


    aObj.foo = "foo";
    aObj.bar = "bar";
    aObj.baz = "baz";

    try {
      ExtGraph aGraph = Graphs.extend(RdfGenerator.asRdf(aObj));

      // we should have the normal field
      assertTrue(aGraph.contains(null, ValueFactoryImpl.getInstance().createURI("urn:foo"), null));

      // but neither of the transient ones
      assertFalse(aGraph.contains(null, ValueFactoryImpl.getInstance().createURI("urn:bar"), null));
      assertFalse(aGraph.contains(null, ValueFactoryImpl.getInstance().createURI("urn:baz"), null));
    }
    catch (InvalidRdfException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here


  /**
   * @inheritDoc
   */
    @Override
  public DataSource create(final Map<String, Object> theMap) throws DataSourceException {
    ExtGraph aGraph = Graphs.extend(Graphs.newGraph());

    if (theMap.containsKey("files")) {
      for (String aFile : theMap.get("files").toString().split(",")) {
        try {
          aGraph.read(new File(aFile.trim()));
        }
        catch (Exception e) {
          throw new DataSourceException(e);
        }
      }
View Full Code Here

    TestPerson aPerson = new TestPerson();

    aPerson.setMBox("mailto:bob@example.org");

    try {
      ExtGraph aGraph = Graphs.extend(RdfGenerator.asRdf(aPerson));

      org.openrdf.model.URI aPersonURI = aGraph.getValueFactory().createURI(aPerson.getRdfId().toString());

      assertEquals(aGraph.size(), 2);

      // the statements should assert that the person is of type foaf:TestPerson
      assertTrue(Sets.newHashSet(aGraph.getTypes(aPersonURI)).contains(FOAF.ontology().Person));

      // and that the mbox is correct
      assertEquals(Graphs.getLiteral(aGraph, aPersonURI, FOAF.ontology().mbox).get().getLabel(), aPerson.getMBox());

      // now lets try with some more properties

      aPerson.setWeight(123.45f);
      aPerson.setBirthday(new Date());
      aPerson.setFirstName("John");
      aPerson.setLastName("Doe");
      aPerson.setLikesVideoGames(true);
      aPerson.setTitle("Sir");

      aPerson.getKnows().add(aJoe);
      aPerson.getKnows().add(aJane);

      aPerson.setWeblogURI(URI.create("http://example.org"));

      aGraph = Graphs.extend(RdfGenerator.asRdf(aPerson));

      assertEquals((Float) Float.parseFloat(aGraph.getLiteral(aPersonURI, TestVocab.ontology().weight).get().getLabel()),
             aPerson.getWeight());

      // this tests if "inferring" from an annotated getter works
      assertEquals(Boolean.valueOf(aGraph.getLiteral(aPersonURI, TestVocab.ontology().likesVideoGames).get().getLabel()),
             aPerson.isLikesVideoGames());

      // and this tests if 'inferring" from an annotated setter works
      // also checking that it properly used the other namespace
      assertEquals(aGraph.getLiteral(aPersonURI, DC.ontology().title).get().getLabel(),
             aPerson.getTitle());

      assertEquals(URI.create(GraphUtil.getUniqueObject(aGraph, aPersonURI, DC.ontology().publisher).stringValue()),
             aPerson.getWeblogURI());

      assertEquals(aGraph.getLiteral(aPersonURI, FOAF.ontology().firstName).get().getLabel(),
             aPerson.getFirstName());

      assertEquals(aGraph.getLiteral(aPersonURI, FOAF.ontology().surname).get().getLabel(),
             aPerson.getLastName());

      assertEquals(aGraph.getLiteral(aPersonURI, RDFS.LABEL).get().getLabel(),
             aPerson.getLabel());

      List aKnows = Lists.newArrayList(GraphUtil.getObjects(aGraph, aPersonURI, FOAF.ontology().knows));

      assertEquals(aKnows.size(), 2);

      assertTrue(aKnows.contains(aGraph.getValueFactory().createURI(aJane.getRdfId().toString())));
      assertTrue(aKnows.contains(aGraph.getValueFactory().createURI(aJoe.getRdfId().toString())));
    }
    catch (InvalidRdfException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

TOP

Related Classes of com.complexible.common.openrdf.model.ExtGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.