예제 #1
0
  public static Model exec(Model model, final Table table, Query query) throws IOException {
    OntModel inferencedModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    ElementData tableElementData =
        new ElementData() {
          @Override
          public Table getTable() {
            return table;
          }
        };
    for (Var var : table.getVars()) {
      tableElementData.add(var);
    }
    ElementGroup elementGroup = new ElementGroup();
    elementGroup.addElement(tableElementData);
    if (query.getQueryPattern() instanceof ElementGroup) {
      for (Element element : ((ElementGroup) query.getQueryPattern()).getElements()) {
        elementGroup.addElement(element);
      }
    } else {
      elementGroup.addElement(query.getQueryPattern());
    }
    query.setQueryPattern(elementGroup);

    //        QueryExecution ex = QueryExecutionFactory.create(query, model);
    QueryExecution ex = ARQFactory.get().createQueryExecution(query, model);
    if (query.isConstructType()) {
      ex.execConstruct(inferencedModel);
    } else {
      inferencedModel.add(ex.execSelect().getResourceModel());
    }
    return inferencedModel;
  }
예제 #2
0
  public static Table getTable(List<List<String>> dataTable) {

    Table table = TableFactory.create();
    Integer rowNumber = 0;
    List<Var> vars = new ArrayList<>();

    for (List<String> rowData : dataTable) {
      if (rowNumber == 0) {
        for (String data : rowData) {
          vars.add(Var.alloc(data));
        }
        table = TableFactory.create(vars);
      } else {
        table.addBinding(toBinding(rowData, vars));
      }
      rowNumber++;
    }
    return table;
  }