Exemplo n.º 1
0
  public static Method create(QuerySolution qs) throws Exception {
    Resource id = (Resource) qs.get("x");
    Literal fullPath = (Literal) qs.get("fullPath");
    Literal name = (Literal) qs.get("name");
    Literal accessModifier = (Literal) qs.get("accessModifier");
    Literal lineStart = (Literal) qs.get("line_start");
    Literal lineEnd = (Literal) qs.get("line_end");
    Resource returnType = (Resource) qs.get("returnType");
    Resource hasParameter = (Resource) qs.get("hasParameter");
    Resource throwsException = (Resource) qs.get("throwsException");
    Resource belongsTo = (Resource) qs.get("belongsTo");

    Method meth = new Method(id.toString(), name.getValue().toString());
    meth.setAccessModifier(accessModifier.getValue().toString());
    meth.setFullPath(fullPath.getValue().toString());
    meth.setLineStart(lineStart.getInt());
    meth.setLineEnd(lineEnd.getInt());
    meth.setReturnType(returnType.toString());
    if (hasParameter != null) {
      meth.setHasParameter(hasParameter.toString());
    }
    if (throwsException != null) {
      meth.setThrowsException(throwsException.toString());
    }
    meth.setBelongsTo(belongsTo.toString());

    return meth;
  }
Exemplo n.º 2
0
  /**
   * Create a JCR value from an RDF node with the given JCR type
   *
   * @param valueFactory
   * @param data
   * @param type
   * @return
   * @throws RepositoryException
   */
  public Value createValue(final ValueFactory valueFactory, final RDFNode data, final int type)
      throws RepositoryException {
    assert (valueFactory != null);

    if (data.isURIResource() && (type == REFERENCE || type == WEAKREFERENCE)) {
      // reference to another node (by path)
      final Node nodeFromGraphSubject =
          session.getNode(graphSubjects.getPathFromSubject(data.asResource()));
      return valueFactory.createValue(nodeFromGraphSubject, type == WEAKREFERENCE);
    } else if (data.isURIResource() || type == URI) {
      // some random opaque URI
      return valueFactory.createValue(data.toString(), PropertyType.URI);
    } else if (data.isResource()) {
      // a non-URI resource (e.g. a blank node)
      return valueFactory.createValue(data.toString(), UNDEFINED);
    } else if (data.isLiteral() && type == UNDEFINED) {
      // the JCR schema doesn't know what this should be; so introspect
      // the RDF and try to figure it out
      final Literal literal = data.asLiteral();
      final RDFDatatype dataType = literal.getDatatype();
      final Object rdfValue = literal.getValue();

      if (rdfValue instanceof Boolean) {
        return valueFactory.createValue((Boolean) rdfValue);
      } else if (rdfValue instanceof Byte
          || (dataType != null && dataType.getJavaClass() == Byte.class)) {
        return valueFactory.createValue(literal.getByte());
      } else if (rdfValue instanceof Double) {
        return valueFactory.createValue((Double) rdfValue);
      } else if (rdfValue instanceof Float) {
        return valueFactory.createValue((Float) rdfValue);
      } else if (rdfValue instanceof Long
          || (dataType != null && dataType.getJavaClass() == Long.class)) {
        return valueFactory.createValue(literal.getLong());
      } else if (rdfValue instanceof Short
          || (dataType != null && dataType.getJavaClass() == Short.class)) {
        return valueFactory.createValue(literal.getShort());
      } else if (rdfValue instanceof Integer) {
        return valueFactory.createValue((Integer) rdfValue);
      } else if (rdfValue instanceof XSDDateTime) {
        return valueFactory.createValue(((XSDDateTime) rdfValue).asCalendar());
      } else {
        return valueFactory.createValue(literal.getString(), STRING);
      }

    } else {
      LOGGER.debug("Using default JCR value creation for RDF literal: {}", data);
      return valueFactory.createValue(data.asLiteral().getString(), type);
    }
  }
Exemplo n.º 3
0
  public void teste() {
    // String name = this.getName();
    String title = "";
    String service = "http://dblp.rkbexplorer.com/sparql";
    String query =
        "PREFIX akt:  <http://www.aktors.org/ontology/portal#> "
            + "PREFIX akt:  <http://www.aktors.org/ontology/portal#> "
            + " SELECT DISTINCT ?name ?title "
            + " WHERE "
            + " { "
            + " ?auth akt:full-name "
            + "\""
            + nameAuthorField
            + "\""
            + " . "
            + " ?pub a akt:Publication-Reference ;"
            + " akt:has-title ?title ;"
            + " akt:has-author ?auth ."
            + " } ";
    QueryExecution queryExecution = QueryExecutionFactory.sparqlService(service, query);
    try {
      ResultSet results = queryExecution.execSelect();
      while (results.hasNext()) {
        QuerySolution querySolution = results.nextSolution();
        // consume title
        Literal literal = querySolution.getLiteral("title");
        title = ("" + literal.getValue());

        // add titulo a lista tituloPublicacao
        this.tituloPublicacao.add(title);
      }
    } catch (QueryExceptionHTTP e) {
      System.out.println(service + " is DOWN");
    } finally {
      queryExecution.close();
    }
  }