Esempio n. 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");
  }