Ejemplo n.º 1
0
  @Test
  public void testUpdate() throws Exception {
    Resource rhmRes = model.getResource(FakeRDFModel.rhm);
    Property name = model.getProperty(foaf + "name");

    Statement nameSt = rhmRes.listProperties(name).nextStatement();
    String originalName = nameSt.getLiteral().getString();

    // assume update is always first remove and then add
    model.remove(nameSt);
    model.add(rhmRes, name, "TESTNAME");

    assert changes.size() == 2;
    assert rhmRes.listProperties(name).toList().size() == 1;
    assert rhmRes.listProperties(name).nextStatement().getLiteral().getString().equals("TESTNAME");

    changes.undo();

    assert changes.size() == 2;
    assert rhmRes.listProperties(name).toList().size() == 1;
    assert rhmRes
        .listProperties(name)
        .nextStatement()
        .getLiteral()
        .getString()
        .equals(originalName);

    changes.redo();

    assert changes.size() == 2;
    assert rhmRes.listProperties(name).toList().size() == 1;
    assert rhmRes.listProperties(name).nextStatement().getLiteral().getString().equals("TESTNAME");
  }
Ejemplo n.º 2
0
  @Test
  public void testDelete() throws Exception {
    Resource rhmRes = model.getResource(FakeRDFModel.rhm);

    Model toRemove = ModelFactory.createDefaultModel();
    toRemove.add(model.listStatements(rhmRes, null, (RDFNode) null));
    toRemove.add(model.listStatements(null, null, rhmRes));

    model.remove(toRemove);

    Model foo = changes.get(0).getChange();

    assert changes.size() == 1;
    assert !model.containsResource(rhmRes);

    changes.undo();

    assert changes.size() == 1;
    assert model.containsResource(rhmRes);
    assert model.containsAll(foo);

    changes.redo();

    assert changes.size() == 1;
    assert !model.containsResource(rhmRes);
  }
Ejemplo n.º 3
0
  public Spec(final String spec_filename, final String spec_uri) {
    if (null == spec_filename) {
      throw new RuntimeException("Can't create spec and filename was null");
    }
    Logger log = Logger.getLogger(Spec.class.getName());

    try {
      log.log(Level.INFO, "Attempting to create Spec from {0}", spec_filename);
      Path pt = new Path(spec_filename);
      FileSystem fs = FileSystem.get(new Configuration());
      log.log(Level.INFO, "Opening {0}", spec_filename);
      FSDataInputStream stream = fs.open(pt);
      _model = ModelFactory.createDefaultModel();
      //            _model.setNsPrefixes(getPrefixes());
      RDFReader reader = this._model.getReader("TURTLE");
      log.log(Level.INFO, "Reading {0}", spec_filename);
      reader.read(this._model, stream, "http://put.a.base.in.your.spec/");
      log.log(Level.INFO, "Successfully created Spec from {0}", spec_filename);
      _specResource = _model.getResource(spec_uri);
      if (!_model.containsResource(_specResource)) {
        log.log(
            Level.WARNING,
            "Spec file {0} does not contain spec {1}",
            new Object[] {spec_filename, spec_uri});
        throw new RuntimeException(
            "Spec file " + spec_filename + " does not contain spec " + spec_uri);
      }
    } catch (IOException ex) {
      log.log(Level.SEVERE, "Caught IOException, converting to RuntimeException", ex);
      throw new RuntimeException(ex);
    }
  }
Ejemplo n.º 4
0
 /**
  * Determine whether the given property is recognized and treated specially by this reasoner. This
  * is a convenience packaging of a special case of getCapabilities.
  *
  * @param property the property which we want to ask the reasoner about, given as a Node since
  *     this is part of the SPI rather than API
  * @return true if the given property is handled specially by the reasoner.
  */
 @Override
 public boolean supportsProperty(Property property) {
   if (factory == null) return false;
   Model caps = factory.getCapabilities();
   Resource root = caps.getResource(factory.getURI());
   return caps.contains(root, ReasonerVocabulary.supportsP, property);
 }
 public Collection<URI> getSupportedFacets(URI needUri) throws NoSuchNeedException {
   List<URI> ret = new LinkedList<URI>();
   Need need = DataAccessUtils.loadNeed(needRepository, needUri);
   Model content = rdfStorageService.loadContent(need);
   if (content == null) return ret;
   Resource baseRes = content.getResource(content.getNsPrefixURI(""));
   StmtIterator stmtIterator = baseRes.listProperties(WON.HAS_FACET);
   while (stmtIterator.hasNext()) {
     RDFNode object = stmtIterator.nextStatement().getObject();
     if (object.isURIResource()) {
       ret.add(URI.create(object.toString()));
     }
   }
   return ret;
 }
Ejemplo n.º 6
0
 /** Run a single test of any sort, performing any appropriate logging and error reporting. */
 public void runTest(String test) {
   runTest(testDefinitions.getResource(test));
 }
Ejemplo n.º 7
0
/** Vocabulary definitions from file:vocabularies/owl.owl */
public class OWL {
  /** The RDF model that holds the vocabulary terms */
  private static Model m_model = ModelFactory.createDefaultModel();

  /** The namespace of the vocabulary as a string ({@value}) */
  public static final String NS = "http://www.w3.org/2002/07/owl#";

  /**
   * The namespace of the vocabulary as a string
   *
   * @see #NS
   */
  public static String getURI() {
    return NS;
  }

  /** The namespace of the vocabulary as a resource */
  public static final Resource NAMESPACE = m_model.createResource(NS);

  /** A resource that denotes the OWL-full sublanguage of OWL */
  public static final Resource FULL_LANG = m_model.getResource(getURI());

  /** A resource, not officially sanctioned by WebOnt, that denotes the OWL-DL sublanguage of OWL */
  public static final Resource DL_LANG =
      m_model.getResource("http://www.w3.org/TR/owl-features/#term_OWLDL");

  /**
   * A resource, not officially sanctioned by WebOnt, that denotes the OWL-Lite sublanguage of OWL
   */
  public static final Resource LITE_LANG =
      m_model.getResource("http://www.w3.org/TR/owl-features/#term_OWLLite");

  // Vocabulary properties
  ///////////////////////////

  public static final Property maxCardinality =
      m_model.createProperty("http://www.w3.org/2002/07/owl#maxCardinality");

  public static final Property versionInfo =
      m_model.createProperty("http://www.w3.org/2002/07/owl#versionInfo");

  public static final Property equivalentClass =
      m_model.createProperty("http://www.w3.org/2002/07/owl#equivalentClass");

  public static final Property distinctMembers =
      m_model.createProperty("http://www.w3.org/2002/07/owl#distinctMembers");

  public static final Property oneOf =
      m_model.createProperty("http://www.w3.org/2002/07/owl#oneOf");

  public static final Property sameAs =
      m_model.createProperty("http://www.w3.org/2002/07/owl#sameAs");

  public static final Property incompatibleWith =
      m_model.createProperty("http://www.w3.org/2002/07/owl#incompatibleWith");

  public static final Property minCardinality =
      m_model.createProperty("http://www.w3.org/2002/07/owl#minCardinality");

  public static final Property complementOf =
      m_model.createProperty("http://www.w3.org/2002/07/owl#complementOf");

  public static final Property onProperty =
      m_model.createProperty("http://www.w3.org/2002/07/owl#onProperty");

  public static final Property equivalentProperty =
      m_model.createProperty("http://www.w3.org/2002/07/owl#equivalentProperty");

  public static final Property inverseOf =
      m_model.createProperty("http://www.w3.org/2002/07/owl#inverseOf");

  public static final Property backwardCompatibleWith =
      m_model.createProperty("http://www.w3.org/2002/07/owl#backwardCompatibleWith");

  public static final Property differentFrom =
      m_model.createProperty("http://www.w3.org/2002/07/owl#differentFrom");

  public static final Property priorVersion =
      m_model.createProperty("http://www.w3.org/2002/07/owl#priorVersion");

  public static final Property imports =
      m_model.createProperty("http://www.w3.org/2002/07/owl#imports");

  public static final Property allValuesFrom =
      m_model.createProperty("http://www.w3.org/2002/07/owl#allValuesFrom");

  public static final Property unionOf =
      m_model.createProperty("http://www.w3.org/2002/07/owl#unionOf");

  public static final Property hasValue =
      m_model.createProperty("http://www.w3.org/2002/07/owl#hasValue");

  public static final Property someValuesFrom =
      m_model.createProperty("http://www.w3.org/2002/07/owl#someValuesFrom");

  public static final Property disjointWith =
      m_model.createProperty("http://www.w3.org/2002/07/owl#disjointWith");

  public static final Property cardinality =
      m_model.createProperty("http://www.w3.org/2002/07/owl#cardinality");

  public static final Property intersectionOf =
      m_model.createProperty("http://www.w3.org/2002/07/owl#intersectionOf");

  // Vocabulary classes
  ///////////////////////////

  public static final Resource Thing =
      m_model.createResource("http://www.w3.org/2002/07/owl#Thing");

  public static final Resource DataRange =
      m_model.createResource("http://www.w3.org/2002/07/owl#DataRange");

  public static final Resource Ontology =
      m_model.createResource("http://www.w3.org/2002/07/owl#Ontology");

  public static final Resource DeprecatedClass =
      m_model.createResource("http://www.w3.org/2002/07/owl#DeprecatedClass");

  public static final Resource AllDifferent =
      m_model.createResource("http://www.w3.org/2002/07/owl#AllDifferent");

  public static final Resource DatatypeProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#DatatypeProperty");

  public static final Resource SymmetricProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#SymmetricProperty");

  public static final Resource TransitiveProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#TransitiveProperty");

  public static final Resource DeprecatedProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#DeprecatedProperty");

  public static final Resource AnnotationProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#AnnotationProperty");

  public static final Resource Restriction =
      m_model.createResource("http://www.w3.org/2002/07/owl#Restriction");

  public static final Resource Class =
      m_model.createResource("http://www.w3.org/2002/07/owl#Class");

  public static final Resource OntologyProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#OntologyProperty");

  public static final Resource ObjectProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#ObjectProperty");

  public static final Resource FunctionalProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#FunctionalProperty");

  public static final Resource InverseFunctionalProperty =
      m_model.createResource("http://www.w3.org/2002/07/owl#InverseFunctionalProperty");

  public static final Resource Nothing =
      m_model.createResource("http://www.w3.org/2002/07/owl#Nothing");

  // Vocabulary individuals
  ///////////////////////////

}