static Set<Resource> subjects(Model model, Property p, RDFNode r) {
   Set<Resource> subjects = new HashSet<>();
   ResIterator it = model.listSubjectsWithProperty(p, r);
   while (it.hasNext()) subjects.add(it.next().asResource());
   it.close();
   return subjects;
 }
예제 #2
0
  public static void main(String[] args) {
    Store store = HBaseRdfFactory.connectStore("Store/hbaserdf-simple.ttl");
    store.getTableFormatter().format();

    Model model = HBaseRdfFactory.connectDefaultModel(store);

    model.add(
        model.createResource("http://example.org/person#John"),
        VCARD.FN,
        model.asRDFNode(Node.createLiteral("John Smith")));
    model.add(
        model.createResource("http://example.org/person#John"),
        VCARD.EMAIL,
        model.asRDFNode(Node.createLiteral("*****@*****.**")));
    model.add(
        model.createResource("http://example.org/person#Jim"),
        VCARD.FN,
        model.asRDFNode(Node.createLiteral("Jim Mason")));
    model.add(
        model.createResource("http://example.org/person#Jim"),
        VCARD.EMAIL,
        model.asRDFNode(Node.createLiteral("*****@*****.**")));
    model.add(
        model.createResource("http://example.org/person#Bob"),
        VCARD.FN,
        model.asRDFNode(Node.createLiteral("Bob Brown")));
    model.add(
        model.createResource("http://example.org/person#Bob"),
        VCARD.EMAIL,
        model.asRDFNode(Node.createLiteral("*****@*****.**")));

    StmtIterator iter = model.listStatements();
    while (iter.hasNext()) {
      System.out.println(iter.next().toString());
    }

    iter = model.getResource("http://example.org/person#John").listProperties();
    while (iter.hasNext()) {
      System.out.println(iter.next().toString());
    }

    ResIterator resIter = model.listSubjects();
    while (resIter.hasNext()) {
      System.out.println(resIter.next().toString());
    }

    String query =
        " PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> "
            + " SELECT ?x "
            + " WHERE "
            + " { "
            + " 		<http://example.org/person#John> vcard:FN ?x "
            + " } ";

    QueryExecution qe = QueryExecutionFactory.create(query, model);
    ResultSet rs = qe.execSelect();
    ResultSetFormatter.out(rs);
  }
예제 #3
0
  @Override
  public List<Entity> getEntities(String text) {
    List<Entity> list = new ArrayList<>();
    try {
      String foxJSONOutput = doTASK(text);

      JSONParser parser = new JSONParser();
      JSONArray jsonArray = (JSONArray) parser.parse(foxJSONOutput);
      String output =
          URLDecoder.decode((String) ((JSONObject) jsonArray.get(0)).get("output"), "UTF-8");

      String baseURI = "http://dbpedia.org";
      Model model = ModelFactory.createDefaultModel();
      RDFReader r = model.getReader("N3");
      r.read(model, new StringReader(output), baseURI);

      ResIterator iter = model.listSubjects();
      while (iter.hasNext()) {
        Resource next = iter.next();
        StmtIterator statementIter = next.listProperties();
        Entity ent = new Entity();
        while (statementIter.hasNext()) {
          Statement statement = statementIter.next();
          String predicateURI = statement.getPredicate().getURI();
          if (predicateURI.equals("http://www.w3.org/2000/10/annotation-ns#body")) {
            ent.label = statement.getObject().asLiteral().getString();
          } else if (predicateURI.equals("http://ns.aksw.org/scms/means")) {
            String uri = statement.getObject().asResource().getURI();
            String encode = uri.replaceAll(",", "%2C");
            ent.URI = encode;
          } else if (predicateURI.equals("http://ns.aksw.org/scms/beginIndex")) {
            ent.start = statement.getObject().asLiteral().getInt();
          } else if (predicateURI.equals("http://ns.aksw.org/scms/endIndex")) {
            ent.end = statement.getObject().asLiteral().getInt();
          }
        }
        list.add(ent);
      }

    } catch (IOException | ParseException e) {
      log.error("Could not call FOX for NER/NED", e);
    }
    return list;
  }
  public static void main(String[] args) {
    Model adapterModel =
        OntologyModelUtil.loadModel("ontologies/docker.ttl", IMessageBus.SERIALIZATION_TURTLE);

    Property propCommand =
        adapterModel.getProperty(adapterModel.getNsPrefixURI("docker"), "command");

    Model m = OntologyModelUtil.loadModel("test.ttl", IMessageBus.SERIALIZATION_TURTLE);

    ResIterator rs = m.listResourcesWithProperty(propCommand);
    while (rs.hasNext()) {
      Resource r = rs.next();
      Statement c = r.getProperty(propCommand);

      Resource listHead = c.getObject().asResource();
      LinkedList<String> output = new LinkedList<String>();
      extractList(output, listHead);

      for (String elem : output) {
        System.out.println("elem: " + elem);
      }
    }
  }