public void deleteProperty(String yourInstance, String yourProperty) {

    // 查找属性URI
    String sparqlProperty =
        "SELECT ?property WHERE{?property <http://www.w3.org/2000/01/rdf-schema#label> '"
            + yourProperty
            + "'@zh.}";
    ResultSet resultsProperty = Result(sparqlProperty);
    QuerySolution solutionProperty = null;
    while (resultsProperty.hasNext()) solutionProperty = resultsProperty.next();
    // System.out.println(sparqlProperty);
    // System.out.println(solutionProperty.get("?property"));

    // 查找属性值
    String sparqlPropertyValue =
        "SELECT ?propertyValue WHERE{<http://www.semanticweb.org/administrator/ontologies/2015/6/untitled-ontology-31#'"
            + yourInstance
            + "'@zh> <"
            + solutionProperty.get("?property")
            + "> "
            + "?propertyValue}";
    ResultSet resultsPropertyValue = Result(sparqlPropertyValue);
    QuerySolution solutionPropertyValue = null;
    while (resultsPropertyValue.hasNext()) solutionPropertyValue = resultsPropertyValue.next();
    // System.out.println(sparqlPropertyValue);
    // System.out.println(solutionPropertyValue.get("?propertyValue"));

    String string1 = solutionPropertyValue.toString();
    int i = string1.length();
    i = i - 2;
    String string2 = (String) string1.subSequence(19, i);
    System.out.println(string2);

    // 删除实例属性
    String sparqlDeleteProperty =
        "delete data{<http://www.semanticweb.org/administrator/ontologies/2015/6/untitled-ontology-31#'"
            + yourInstance
            + "'@zh> <"
            + solutionProperty.get("?property")
            + "> "
            + string2
            + "}";
    // System.out.println(sparqlDeleteProperty);

    UpdateRequest updateProperty = UpdateFactory.create(sparqlDeleteProperty);
    UpdateProcessor qexecProperty =
        UpdateExecutionFactory.createRemote(updateProperty, UPDATE_SERVER);
    qexecProperty.execute();
  }
Exemplo n.º 2
0
  public static List<String> converteRetornoSparql(ResultSet resultado) {

    List<String> lista = new ArrayList<String>();
    if (resultado == null) return lista;

    while (resultado.hasNext()) {
      com.hp.hpl.jena.query.QuerySolution soln = resultado.nextSolution();

      String caminhoFull = soln.toString();

      lista.add(caminhoFull);
    }

    return lista;
  }