You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ij...@apache.org on 2012/01/17 01:42:03 UTC
svn commit: r1232242 [1/4] - in /incubator/jena/Jena2/Examples/trunk: ./
bin/ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/jena/
src/main/java/org/apache/jena/example/ src/main/java/org/apache/jena...
Author: ijd
Date: Tue Jan 17 00:42:02 2012
New Revision: 1232242
URL: http://svn.apache.org/viewvc?rev=1232242&view=rev
Log:
Initial commit of shared space for Jena example programs
Added:
incubator/jena/Jena2/Examples/trunk/README.md
incubator/jena/Jena2/Examples/trunk/bin/
incubator/jena/Jena2/Examples/trunk/bin/get-data
incubator/jena/Jena2/Examples/trunk/pom.xml (with props)
incubator/jena/Jena2/Examples/trunk/src/
incubator/jena/Jena2/Examples/trunk/src/main/
incubator/jena/Jena2/Examples/trunk/src/main/java/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/Base.java (with props)
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/CheeseBase.java (with props)
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/HelloWorld.java (with props)
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/
incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/PizzaSparqlNoInf.java (with props)
incubator/jena/Jena2/Examples/trunk/src/main/resources/
incubator/jena/Jena2/Examples/trunk/src/main/resources/data/
incubator/jena/Jena2/Examples/trunk/src/main/resources/data/cheeses-0.1.ttl
incubator/jena/Jena2/Examples/trunk/src/main/resources/data/pizza.owl.rdf
incubator/jena/Jena2/Examples/trunk/src/main/resources/ontologies/
incubator/jena/Jena2/Examples/trunk/src/main/resources/ontologies/cheese.ttl
incubator/jena/Jena2/Examples/trunk/src/test/
incubator/jena/Jena2/Examples/trunk/src/test/java/
incubator/jena/Jena2/Examples/trunk/src/test/java/org/
incubator/jena/Jena2/Examples/trunk/src/test/java/org/apache/
incubator/jena/Jena2/Examples/trunk/src/test/java/org/apache/jena_examples/
incubator/jena/Jena2/Examples/trunk/src/test/java/org/apache/jena_examples/AppTest.java (with props)
Added: incubator/jena/Jena2/Examples/trunk/README.md
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/README.md?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/README.md (added)
+++ incubator/jena/Jena2/Examples/trunk/README.md Tue Jan 17 00:42:02 2012
@@ -0,0 +1,27 @@
+# Jena Examples
+
+A collection of complete, runnable Jena examples to illustrate various
+aspects of programming using RDF with Jena.
+
+## Cheese ontology examples
+
+Paolo Castagna is building a collection of RDF descriptions of the cheeses
+of the world (see [Paolo's github account](https://github.com/castagna/cheese)
+for the latest version). These examples use the cheese data, or its associated
+ontology, as examples.
+
+### Hello World
+
+A very simple just-get-started example program that shows creating a memory
+model, loading an RDF data file, and iterating over the model to select cheeses.
+
+
+## Pizza ontology examples
+
+The pizza ontology is widely used in ontology tutorials and classes. These
+examples use that ontology as an illustration.
+
+### Pizza SPARQL (no inference)
+
+Using SPARQL to query the class expressions in the Pizza ontology without relying on
+RDF inference.
Added: incubator/jena/Jena2/Examples/trunk/bin/get-data
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/bin/get-data?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/bin/get-data (added)
+++ incubator/jena/Jena2/Examples/trunk/bin/get-data Tue Jan 17 00:42:02 2012
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+echo Getting JISC organizations
+wget -O src/main/resources/data/jisc-organizations.rdf http://www.ovod.net/wilbert/linkedData/jiscMUorganisations.rdf
+java jena.rdfcat -o Turtle src/main/resources/data/jisc-organizations.rdf > src/main/resources/data/jisc-organizations.ttl
+
+# split the file up
+arq --data=src/main/resources/data/jisc-organizations.ttl "describe ?uni where {?uni <http://www.jiscmu.ac.uk/schema/muweb/Sector> 'Higher Education'}" > src/main/resources/data/he.ttl
+arq --data=src/main/resources/data/jisc-organizations.ttl "describe ?uni where {?uni <http://www.jiscmu.ac.uk/schema/muweb/Sector> 'Further Education'}" > src/main/resources/data/fe.ttl
+
Added: incubator/jena/Jena2/Examples/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/pom.xml?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/pom.xml (added)
+++ incubator/jena/Jena2/Examples/trunk/pom.xml Tue Jan 17 00:42:02 2012
@@ -0,0 +1,64 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-examples</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>jena-examples</name>
+ <description>A collection of example code illustrating uses of Apache Jena</description>
+ <url>http://incubator.apache.org/jena</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <organization>
+ <name>Apache Software Foundation</name>
+ <url>http://apache.org</url>
+ </organization>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-tdb</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>apache-repo-snapshots</id>
+ <url>http://repository.apache.org/content/repositories/snapshots/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+
+ <repository>
+ <id>apache-repo-releases</id>
+ <url>http://repository.apache.org/content/repositories/releases/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ </repositories>
+
+</project>
Propchange: incubator/jena/Jena2/Examples/trunk/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/Base.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/Base.java?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/Base.java (added)
+++ incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/Base.java Tue Jan 17 00:42:02 2012
@@ -0,0 +1,140 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.example;
+
+
+// Imports
+///////////////
+import org.apache.commons.cli.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>Base file for <em>Getting Started</em> examples. A place to put shared
+ * implementation, constants, etc.</p>
+ */
+public abstract class Base
+ implements Runnable
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /** Relative path to the directory containing sample data */
+ public static final String DATA_DIR = "./src/main/resources/data/";
+
+ /** Relative path to the directory containing sample ontologies */
+ public static final String ONTOLOGIES_DIR = "./src/main/resources/ontologies/";
+
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( Base.class );
+
+ /** Command line options */
+ private static Options options;
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ private CommandLine commandLine;
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * Add a command line option for the application, which will be matched
+ * against the command-line args at run time.
+ * @param opt Short option or null, e.g. <code>-a</code>
+ * @param longOpt Long option name or null, e.g. <code>--data</code>
+ * @param hasArg If true, the option will take an argument, e.g. <code>--dataFile foo.txt</code>
+ * @param description Argument description as it will appear in the usage message
+ */
+ public static void addOption( String opt, String longOpt, boolean hasArg, String description ) {
+ if (Base.options == null) {
+ Base.options = new Options();
+ }
+ options.addOption( opt, longOpt, hasArg, description );
+ }
+
+ /**
+ * Return the list of options, ensuring that it is non-null
+ * @return
+ */
+ public static Options getOptions() {
+ if (Base.options == null) {
+ Base.options = new Options();
+ }
+ return options;
+ }
+
+ /**
+ * Set up the command line arguments according to the options. If the
+ * arguments do not parse, print an error message and exit with status 1.
+ * @param args
+ */
+ public Base setArgs( String[] args ) {
+ if (args == null) {args = new String[] {};}
+
+ try {
+ commandLine = new GnuParser().parse( Base.getOptions(), args );
+ }
+ catch (ParseException e) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "", options );
+ System.exit( 1 );
+ }
+
+ // allow method chaining
+ return this;
+ }
+
+ /**
+ * Return true if the given option is set in the given command line
+ * @param opt Option to test for, e.g. <code>data</code>
+ * @return
+ */
+ public boolean hasArg( String opt ) {
+ if (commandLine == null) {
+ System.err.println( "Command line arguments have not been set yet. See setArgs( String[] args )" );
+ System.exit( 1 );
+ }
+ return commandLine.hasOption( opt );
+ }
+
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Propchange: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/Base.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/CheeseBase.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/CheeseBase.java?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/CheeseBase.java (added)
+++ incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/CheeseBase.java Tue Jan 17 00:42:02 2012
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.example;
+
+
+// Imports
+///////////////
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>Base class for cheese-ontology based examples. Declares
+ * common namespaces and provides some basic utilities.</p>
+ */
+public abstract class CheeseBase extends Base
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ public static final String CHEESE_SCHEMA = "http://data.kasabi.com/dataset/cheese/schema/";
+ public static final String CHEESE_DATA = "http://data.kasabi.com/dataset/cheese/";
+
+ public static final String CHEESE_SCHEMA_FILE = ONTOLOGIES_DIR + "cheese.ttl";
+ public static final String CHEESE_DATA_FILE = DATA_DIR + "cheeses-0.1.ttl";
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( CheeseBase.class );
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Propchange: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/CheeseBase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/HelloWorld.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/HelloWorld.java?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/HelloWorld.java (added)
+++ incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/HelloWorld.java Tue Jan 17 00:42:02 2012
@@ -0,0 +1,157 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.example.helloworld;
+
+
+// Imports
+///////////////
+import org.apache.jena.example.CheeseBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.util.FileManager;
+import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
+
+/**
+ * <h2>Apache Jena Getting Started Guide - Step 1: Hello World</h2>
+ * <p>
+ * In this step, we illustrate the basic operations of getting some data into
+ * a Java program, finding some data, and showing some output.
+ * </p>
+ */
+public class HelloWorld
+ extends CheeseBase
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( HelloWorld.class );
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * Main entry point for running this example. Since every sub-class
+ * will be {@link Runnable}, we create an instance, stash the
+ * command-line args where we can retrieve them later, and
+ * invoke {@link #run}
+ */
+ public static void main( String[] args ) {
+ new HelloWorld().setArgs( args ).run();
+ }
+
+ public void run() {
+ // creates a new, empty in-memory model
+ Model m = ModelFactory.createDefaultModel();
+
+ // load some data into the model
+ FileManager.get().readModel( m, CHEESE_DATA_FILE );
+
+ // generate some output
+ showModelSize( m );
+ listCheeses( m );
+ }
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ /**
+ * Show the size of the model on stdout
+ */
+ protected void showModelSize( Model m ) {
+ System.out.println( String.format( "The model contains %d triples", m.size() ) );
+ }
+
+ /**
+ * List the names of cheeses to stdout
+ */
+ protected void listCheeses( Model m ) {
+ Resource cheeseClass = m.getResource( CHEESE_SCHEMA + "Cheese" );
+
+ StmtIterator i = m.listStatements( null, RDF.type, cheeseClass );
+
+ while (i.hasNext()) {
+ Resource cheese = i.next().getSubject();
+ String label = getEnglishLabel( cheese );
+ System.out.println( String.format( "Cheese %s has name: %s", cheese.getURI(), label ) );
+ }
+ }
+
+ /**
+ * Get the English-language label for a given resource. In general, a resource
+ * may have zero, one or many labels. In this case, we happen to know that
+ * the cheese resources have mutlilingual labels, so we pick out the English one
+ * @param cheese
+ * @return
+ */
+ protected String getEnglishLabel( Resource cheese ) {
+ StmtIterator i = cheese.listProperties( RDFS.label );
+ while (i.hasNext()) {
+ Literal l = i.next().getLiteral();
+
+ if (l.getLanguage() != null && l.getLanguage().equals( "en")) {
+ // found the English language label
+ return l.getLexicalForm();
+ }
+ }
+
+ return "A Cheese with No Name!";
+ }
+
+ /**
+ * Get the value of a property as a string, allowing for missing properties
+ * @param r A resource
+ * @param p The property whose value is wanted
+ * @return The value of the <code>p</code> property of <code>r</code> as a string
+ */
+ protected String getValueAsString( Resource r, Property p ) {
+ Statement s = r.getProperty( p );
+ if (s == null) {
+ return "";
+ }
+ else {
+ return s.getObject().isResource() ? s.getResource().getURI() : s.getString();
+ }
+ }
+
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Propchange: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/helloworld/HelloWorld.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/PizzaSparqlNoInf.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/PizzaSparqlNoInf.java?rev=1232242&view=auto
==============================================================================
--- incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/PizzaSparqlNoInf.java (added)
+++ incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/PizzaSparqlNoInf.java Tue Jan 17 00:42:02 2012
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.example.pizza;
+
+
+// Imports
+///////////////
+import org.apache.jena.example.Base;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.ontology.OntModel;
+import com.hp.hpl.jena.ontology.OntModelSpec;
+import com.hp.hpl.jena.query.*;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.util.FileManager;
+import com.hp.hpl.jena.vocabulary.OWL;
+import com.hp.hpl.jena.vocabulary.RDFS;
+
+/**
+ * <p>TODO class comment</p>
+ */
+public class PizzaSparqlNoInf extends Base
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ // Directory where we've stored the local data files, such as pizza.rdf.owl
+ public static final String SOURCE = "./src/main/resources/data/";
+
+ // Pizza ontology namespace
+ public static final String PIZZA_NS = "http://www.co-ode.org/ontologies/pizza/pizza.owl#";
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( PizzaSparqlNoInf.class );
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * @param args
+ */
+ public static void main( String[] args ) {
+ new PizzaSparqlNoInf().setArgs( args ).run();
+ }
+
+ public void run() {
+ OntModel m = getModel();
+ loadData( m );
+ String prefix = "prefix pizza: <" + PIZZA_NS + ">\n" +
+ "prefix rdfs: <" + RDFS.getURI() + ">\n" +
+ "prefix owl: <" + OWL.getURI() + ">\n";
+
+
+ showQuery( m,
+ prefix +
+ "select ?pizza where {?pizza a owl:Class ; " +
+ " rdfs:subClassOf ?restriction.\n" +
+ " ?restriction owl:onProperty pizza:hasTopping ;" +
+ " owl:someValuesFrom pizza:PeperoniSausageTopping" +
+ "}" );
+ }
+
+ protected OntModel getModel() {
+ return ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
+ }
+
+ protected void loadData( Model m ) {
+ FileManager.get().readModel( m, SOURCE + "pizza.owl.rdf" );
+ }
+
+ protected void showQuery( Model m, String q ) {
+ Query query = QueryFactory.create( q );
+ QueryExecution qexec = QueryExecutionFactory.create( query, m );
+ try {
+ ResultSet results = qexec.execSelect();
+ ResultSetFormatter.out( results, m );
+ }
+ finally {
+ qexec.close();
+ }
+
+ }
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Propchange: incubator/jena/Jena2/Examples/trunk/src/main/java/org/apache/jena/example/pizza/PizzaSparqlNoInf.java
------------------------------------------------------------------------------
svn:mime-type = text/plain