Example #1
0
  public static void main(String[] args) {
    // create an empty model
    Model model = ModelFactory.createDefaultModel();

    // use the FileManager to find the input file
    String inputFileName = "src/main/resources/lab-3.ttl";
    InputStream in = FileManager.get().open(inputFileName);
    if (in == null) {
      throw new IllegalArgumentException("File: " + inputFileName + " not found");
    }

    // read the Turtle file
    model.read(in, null, "TTL");

    // get the inferred mode
    /* The getDeductionsFunction somehow returns the incorrect answer, so I have to use the deprecated class 'Filter'. */
    InfModel infModel = ModelFactory.createRDFSModel(model);
    ExtendedIterator<Statement> stmts =
        infModel
            .listStatements()
            .filterDrop(
                new Filter<Statement>() {
                  @Override
                  public boolean accept(Statement o) {
                    return model.contains(o);
                  }
                });
    Model deductionsModel = ModelFactory.createDefaultModel().add(new StmtIteratorImpl(stmts));

    // list new RDFS-inferred triples about 'Museion'
    outputInfo(deductionsModel, "museion");

    // list new RDFS-inferred triples about 'Chicken Hut'
    outputInfo(deductionsModel, "chickenHut");
  }
Example #2
0
  @BeforeClass
  public static void beforeClass() {
    graphData = ConfigTest.getTestingDataRoot() + "/Data/solver-data.ttl";
    graph = TDBFactory.createDatasetGraph().getDefaultGraph();
    Model m = ModelFactory.createModelForGraph(graph);
    FileManager.get().readModel(m, graphData);

    pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("", "http://example/");
  }
  public static void main(String args[]) {
    String filename = "example5.rdf";

    // Create an empty model
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);

    // Use the FileManager to find the input file
    InputStream in = FileManager.get().open(filename);

    if (in == null) throw new IllegalArgumentException("File: " + filename + " not found");

    // Read the RDF/XML file
    model.read(in, null);

    // Create a new class named "Researcher"
    OntClass researcher = model.createClass(ns + "Researcher");

    // ** TASK 6.1: Create a new class named "University" **
    OntClass university = model.createClass(ns + "University");

    // ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
    model.getOntClass(ns + "Person").addSubClass(researcher);

    // ** TASK 6.3: Create a new property named "worksIn" **
    Property worksIn = model.createProperty(ns + "worksIn");

    // ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
    Individual jane = researcher.createIndividual(ns + "JaneSmith");

    // ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
    jane.addProperty(VCARD.FN, "Jane Smith");
    jane.addProperty(VCARD.Given, "Jane");
    jane.addProperty(VCARD.Family, "Smith");

    // ** TASK 6.6: Add UPM as the university where John Smith works **
    Individual john = model.getIndividual(ns + "JohnSmith");
    Individual upm = university.createIndividual(ns + "UPM");
    john.addProperty(worksIn, upm);

    model.write(System.out, "RDF/XML-ABBREV");
  }
 /**
  * Test of whenRequiredByAssembler method, of class SDBConnect. What a terrible test. statics are
  * bad!
  */
 @Test
 public void testWhenRequiredByAssembler() {
   Model config = FileManager.get().loadModel("basic.ttl");
   AssemblerHelp.loadArbitraryClasses(new AssemblerGroup.ExpandingAssemblerGroup(), config);
   assertTrue("Assembler loadClass initialised connector", SDBConnect.initialised);
 }
Example #5
0
 /**
  * Assemble a dataset from the model in a file
  *
  * @param filename The filename
  * @param resourceURI URI for the dataset to assembler
  * @return Dataset
  */
 public static Dataset assemble(final String filename, final String resourceURI) {
   final Model model = FileManager.get().loadModel(filename);
   final Resource r = model.createResource(resourceURI);
   return assemble(r);
 }
Example #6
0
 /**
  * Assemble a dataset from the model in a file
  *
  * @param filename The filename
  * @return Dataset
  */
 public static Dataset assemble(final String filename) {
   final Model model = FileManager.get().loadModel(filename);
   return assemble(model);
 }