Esempio n. 1
0
  public static boolean equalResources(Resource t, Resource that) throws ModelException {

    return t.getURI().equals(that.getURI());

    /*

       boolean b = false;

       String tns = t.getNamespace();
       String tn = t.getLocalName();

       String thatns = that.getNamespace();
       String thatn = that.getLocalName();

       //    System.err.print("Comparing " + t + " vs " + that + ": ");

       if(thatns == null) {
         if(tns == null) { // (null, null)
    //	System.err.println("true");
    return thatn.equals(tn);
         } else // (null, not null) maybe "that" did not detect names
    b = thatn.equals(t.getURI());
       } else {
         if(tns != null) // (not null, not null)
    b = thatn.equals(tn) && thatns.equals(tns);
         else // (not null, null) maybe "this" did not detect names
    b = that.getURI().equals(tn);
       }

       if(b)
         return true;

       // else we need to check whether different namespace splitting is used

       if((tns != null ? tns.length() : 0) + (tn != null ? tn.length() : 0) ==
          (thatns != null ? thatns.length() : 0) + (thatn != null ? thatn.length() : 0)) {

         b = t.getURI().equals(that.getURI());

       }

       //    System.err.println("" + b);
       return b;
       */
  }
Esempio n. 2
0
  /** Converts an ordinal property to an integer. */
  public static int getOrd(Resource r) throws ModelException {

    if (r == null) return -1;

    String uri = r.toString();
    if (!isRDF(uri)) return -1;

    int pos = getNamespaceEnd(uri);
    if (pos > 0 && pos + 1 < uri.length()) {
      try {
        int n = Integer.parseInt(uri.substring(pos + 1));
        if (n >= 1) return n;
      } catch (Exception any) {
      }
    }
    return -1;
  }
Esempio n. 3
0
  public static Statement replaceNamespace(
      Statement st, String o, String n, NodeFactory f, Map o2n, Set resourcesToIgnore)
      throws ModelException {

    boolean replaced = false;
    Resource subj = st.subject();
    Resource pred = st.predicate();
    RDFNode obj = st.object();

    if (obj instanceof Resource
        && !(obj instanceof Statement)
        && o.equals(((Resource) obj).getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(obj))) {

      replaced = true;
      Resource r = f.createResource(n, ((Resource) obj).getLocalName());
      if (o2n != null) o2n.put(obj, r);
      obj = r;
    }

    if (o.equals(subj.getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(subj))) {

      replaced = true;
      Resource r = f.createResource(n, subj.getLocalName());
      if (o2n != null) o2n.put(subj, r);
      subj = r;
    }

    if (o.equals(pred.getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(pred))) {

      replaced = true;
      Resource r = f.createResource(n, pred.getLocalName());
      if (o2n != null) o2n.put(pred, r);
      pred = r;
    }
    return replaced ? f.createStatement(subj, pred, obj) : st;
  }
Esempio n. 4
0
  /** Extracts the namespace prefix out of a URI. */
  public static String getNamespace(Resource r) throws ModelException {

    String ns = r.getNamespace();
    return ns != null ? ns : guessNamespace(r.getURI());
  }
Esempio n. 5
0
  /**
   * This method is used to compute the hash code of RDF statements. All implementation of
   * org.w3c.rdf.model.Statement MUST use this method. The hash code is computed as
   *
   * <blockquote>
   *
   * <pre>
   * ((s.hashCode() * 7) + p.hashCode()) * 7 + o.hashCode()
   * </pre>
   *
   * </blockquote>
   */
  public static int statementHashCode(Resource s, Resource p, RDFNode o) {

    return ((s.hashCode() * 7) + p.hashCode()) * 7 + o.hashCode();
  }
Esempio n. 6
0
  public static void collectNamespaces(Resource r, Collection target) throws ModelException {

    String ns = r.getNamespace();
    if (ns != null) target.add(ns);
  }
Esempio n. 7
0
 /** Tests if the resource belongs to the RDF syntax/model namespace. */
 public static boolean isRDF(Resource r) throws ModelException {
   return isRDF(r.getURI());
 }
Esempio n. 8
0
  /** Delivers the name out of the URI (without the namespace prefix). */
  public static String getLocalName(Resource r) throws ModelException {

    if (r.getNamespace() == null) return guessName(r.getURI());
    else return r.getLocalName();
  }