Ejemplo n.º 1
0
  private void _saveOntology() throws Exception {

    if (outputFile.toLowerCase().startsWith("file:")) {
      outputFile = outputFile.substring("file:".length());
    }
    File file = new File(outputFile);

    URI uri = URI.create("file:" + file.getAbsolutePath());

    // TODO NOTE: the format parameter is ignored by SKOAPI alpha; it always
    // uses RDFXMLOntologyFormat
    manager.save(dataset, SKOSFormatExt.RDFXML, uri);

    // To try other possible output format, the OWLAPI can be used directly:
    //		OWLOntologyFormat format =
    //			new RDFXMLOntologyFormat();
    //			new OWLXMLOntologyFormat();
    //			new TurtleOntologyFormat();
    //			new ManchesterOWLSyntaxOntologyFormat();
    //			new LatexOntologyFormat();
    //
    //		owlManager.saveOntology(owlOntology, format, uri);
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {

    /*
     * This example recreates the SKOS dataset in Example2.java, but does so using some convenience methods in fewer lines of code
     *
     */

    try {

      SKOSManager manager = new SKOSManager();

      final String baseURI = "http://www.semanticweb.org/skos/example2.rdf";

      SKOSDataset dataset = manager.createSKOSDataset(URI.create(baseURI));

      SKOSDataFactory df = manager.getSKOSDataFactory();

      List<SKOSEntity> allEntities = new ArrayList<SKOSEntity>();

      // Create a concept scheme identified by a URI
      SKOSConceptScheme conceptScheme1 =
          df.getSKOSConceptScheme(URI.create(baseURI + "#conceptScheme1"));

      // create a set of concepts

      Set<SKOSConcept> concepts = new HashSet<SKOSConcept>();
      concepts.add(df.getSKOSConcept(URI.create(baseURI + "#conceptA")));
      concepts.add(df.getSKOSConcept(URI.create(baseURI + "#conceptB")));
      concepts.add(df.getSKOSConcept(URI.create(baseURI + "#conceptC")));
      concepts.add(df.getSKOSConcept(URI.create(baseURI + "#conceptD")));

      // add all the entities to this set
      allEntities.add(conceptScheme1);
      allEntities.addAll(concepts);

      List<SKOSEntityAssertion> entityAssertions = df.getSKOSEntityAssertions(allEntities);
      List<SKOSObjectRelationAssertion> relationAssertions =
          df.getSKOSObjectRelationAssertions(
              concepts, df.getSKOSInSchemeProperty(), conceptScheme1);

      List<SKOSChange> addAssertions = new ArrayList<SKOSChange>();

      for (SKOSEntityAssertion ass : entityAssertions) {
        addAssertions.add(new AddAssertion(dataset, ass));
      }

      for (SKOSObjectRelationAssertion ass : relationAssertions) {
        addAssertions.add(new AddAssertion(dataset, ass));
      }

      manager.applyChanges(addAssertions);

      manager.save(dataset, SKOSFormatExt.RDFXML, URI.create("file:/Users/simon/tmp/example3.rdf"));

    } catch (SKOSCreationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (SKOSChangeException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (SKOSStorageException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }