Modified: incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java?rev=1161593&r1=1161592&r2=1161593&view=diff ============================================================================== --- incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java (original) +++ incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java Thu Aug 25 15:03:28 2011 @@ -22,7 +22,11 @@ import org.apache.stanbol.cmsadapter.ser /** * This interface aims to enable different implementations to annotate external RDF data with CMS Vocabulary - * annotations defined in {@link CMSAdapterVocabulary}. + * annotations defined in {@link CMSAdapterVocabulary} and generating RDF from the content repository. RDF + * bridges represent a bidirectional transformation between a content repository and an RDF data. + * <p> + * {@link RDFMapper}s are expected to store the RDF data annotated by bridges into the repository and generate + * a base RDF again to be annotated by the bridges. * * @author suat * @@ -31,27 +35,29 @@ public interface RDFBridge { /** * Annotates a {@link Graph} with the properties defined in {@link CMSAdapterVocabulary}. The annotated * graph is expected to contain annotations indicating CMS objects to be created or updated. Furthermore, - * those CMS objects can have parent or property annotations. + * those CMS objects can have parent assertions to indicate an hierarchy. * <p> * In the following RDF, bold resources show possible CMS Vocabulary annotations over an external RDF * data. * <p> * * <pre> + * <font size="3"> * <rdf:RDF * xml:base="http://www.example.org#" * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" * xmlns:foaf="http://xmlns.com/foaf/0.1/" * xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" - * xmlns:cms="http://org.apache.stanbol/cms/"><br> + * xmlns:cms="http://org.apache.stanbol/cms/" + * xmlns:dbp-prop="http://dbpedia.org/property/":><br> * <rdf:Description rdf:about="#TomHanks"> * <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> * <foaf:givenname rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Tom</foaf:givenname> * <foaf:homepage rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://www.tomhanks-online.com</foaf:homepage> * <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Famous actor</rdfs:comment> - * <b><rdf:type rdf:resource="http://org.apache.stanbol/cms/CMSObject"/> - * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TomHanks</cms:name> - * <cms:hasProperty rdf:resource="#homepageProperty"/></b> + * <dbp-prop:child rdf:resource="#ColinHanks"/> + * <b><rdf:type rdf:resource="http://org.apache.stanbol/cms#CMSObject"/> + * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TomHanks</cms:name></b> * </rdf:Description> * * <rdf:Description rdf:about="#ColinHanks"> @@ -59,17 +65,12 @@ public interface RDFBridge { * <foaf:givenname rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Colin</foaf:givenname> * <foaf:homepage rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://colin-hanks.net/</foaf:homepage> * <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Son of Tom Hanks</rdfs:comment> - * <b><rdf:type rdf:resource="http://org.apache.stanbol/cms/CMSObject"/> + * <b><rdf:type rdf:resource="http://org.apache.stanbol/cms#CMSObject"/> * <cms:parentRef rdf:resource="#TomHanks"/> - * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">son</cms:name> - * <cms:hasProperty rdf:resource="#homepageProperty"/></b> + * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">son</cms:name></b> * </rdf:Description> - * - * <b><rdf:Description rdf:about="#homepageProperty"> - * <cms:propertyName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">hasHomepage</cms:propertyName> - * <cms:propertyURI rdf:resource="http://xmlns.com/foaf/0.1/homepage"/> - * </rdf:Description></b> * </rdf:RDF> + * </font> * </pre> * * @param rawRDF @@ -77,4 +78,59 @@ public interface RDFBridge { * @return annotated {@link MGraph}. */ MGraph annotateGraph(Graph rawRDF); + + /** + * This method takes RDF data by an {@link MGraph} and annotates it in a reverse way of + * {@link #annotateGraph(Graph)}. It takes an CMS vocabulary annotated RDF and adds related assertions + * based on the internal implementation. + * <p> + * In the following example bold assertions show some possible annotations by this method + * + * <pre> + * <font size="3"> + * <rdf:RDF + * xml:base="http://www.example.org#" + * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + * xmlns:foaf="http://xmlns.com/foaf/0.1/" + * xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + * xmlns:cms="http://org.apache.stanbol/cms/" + * <dbp-prop:child rdf:resource="#ColinHanks"/><br> + * <rdf:Description rdf:about="#TomHanks"> + * <b><rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> + * <foaf:givenname rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Tom</foaf:givenname> + * <dbp-prop:child rdf:resource="#ColinHanks"/></b> + * <foaf:homepage rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://www.tomhanks-online.com</foaf:homepage> + * <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Famous actor</rdfs:comment> + * <rdf:type rdf:resource="http://org.apache.stanbol/cms#CMSObject"/> + * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TomHanks</cms:name> + * </rdf:Description> + * + * <rdf:Description rdf:about="#ColinHanks"> + * <b><rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> + * <foaf:givenname rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Colin</foaf:givenname></b> + * <foaf:homepage rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://colin-hanks.net/</foaf:homepage> + * <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Son of Tom Hanks</rdfs:comment> + * <rdf:type rdf:resource="http://org.apache.stanbol/cms#CMSObject"/> + * <cms:parentRef rdf:resource="#TomHanks"/> + * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">son</cms:name> + * </rdf:Description> + * </rdf:RDF> + * </font> + * </pre> + * + * @param graph + * {@link MGraph} instance to be enhanced by this bridges + */ + void annotateCMSGraph(MGraph graph); + + /** + * Specifies the content repository path to be affected by this bridge. For example, when a request to + * extract an RDF from the repository is done, CMS objects under this path will be converted to the RDF. + * <p> + * Path annotations should also be done according to this path configuration. Resultant paths are handled + * by {@link RDFMapper}. + * + * @return content repository path configuration + */ + String getCMSPath(); }
Modified: incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java?rev=1161593&r1=1161592&r2=1161593&view=diff ============================================================================== --- incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java (original) +++ incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java Thu Aug 25 15:03:28 2011 @@ -1,10 +1,18 @@ package org.apache.stanbol.cmsadapter.servicesapi.mapping; import org.apache.clerezza.rdf.core.MGraph; +import org.apache.clerezza.rdf.core.UriRef; +import org.apache.stanbol.cmsadapter.servicesapi.helper.CMSAdapterVocabulary; /** * Goal of this interface is to provide a uniform mechanism to store RDF data to JCR or CMIS repositories - * based on cms vocabulary annotations on top of the raw RDF. + * based on CMS vocabulary annotations on top of the raw RDF. CMS vocabulary annotations are basically a few + * {@link UriRef}s defined in {@link CMSAdapterVocabulary} indicating content repository information. + * <p> + * See {@link #storeRDFinRepository(Object, MGraph)} and + * {@link #generateRDFFromRepository(Object, String, MGraph)} to learn behavior of this interface. Former + * method updates the content repository according to annotated RDF and the latter one generates an annotated + * RDF based on the content repository. * * @author suat * @@ -14,60 +22,56 @@ public interface RDFMapper { /** * This method stores the data passed within an {@link MGraph} to repository according * "CMS vocabulary annotations". - * - * In the example RDF below, it is assumed that a CMS Object will be created under the path <b>/rootPath</b> - * (specified as a parameter), having name <b>TomHanks</b>. It will also have a child object named - * <b>son</b> and a property named <b>hasHomepage</b>. Please note that this design can be implemented as - * far as the API to access content repository e.g JCR, CMIS allows. As a result the updates on content - * repository may not be strictly same as the definition above. * <p> - * You can see an example annotated RDF below. Bold assertion shows the CMS Vocabulary annotations: - * - * <pre> - * <rdf:RDF - * xml:base="http://www.example.org#" - * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - * xmlns:foaf="http://xmlns.com/foaf/0.1/" - * xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" - * xmlns:cms="http://org.apache.stanbol/cms/"><br> - * <rdf:Description rdf:about="#TomHanks"> - * <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> - * <foaf:givenname rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Tom</foaf:givenname> - * <foaf:homepage rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://www.tomhanks-online.com</foaf:homepage> - * <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Famous actor</rdfs:comment> - * <b><rdf:type rdf:resource="http://org.apache.stanbol/cms/CMSObject"/> - * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TomHanks</cms:name> - * <cms:hasProperty rdf:resource="#homepageProperty"/></b> - * </rdf:Description> - * - * <rdf:Description rdf:about="#ColinHanks"> - * <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> - * <foaf:givenname rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Colin</foaf:givenname> - * <foaf:homepage rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://colin-hanks.net/</foaf:homepage> - * <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Son of Tom Hanks</rdfs:comment> - * <b><rdf:type rdf:resource="http://org.apache.stanbol/cms/CMSObject"/> - * <cms:parentRef rdf:resource="#TomHanks"/> - * <cms:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">son</cms:name> - * <cms:hasProperty rdf:resource="#homepageProperty"/></b> - * </rdf:Description> - * - * <b><rdf:Description rdf:about="#homepageProperty"> - * <cms:propertyName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">hasHomepage</cms:propertyName> - * <cms:propertyURI rdf:resource="http://xmlns.com/foaf/0.1/homepage"/> - * </rdf:Description></b> - * </rdf:RDF> - * </pre> + * The only required annotation that this method handles is {@link CMSAdapterVocabulary#CMS_OBJECT} + * assertions. This method should create each resource having this assertion as its rdf:type should be + * created as a node/object in the repository. + * <p> + * The name of the CMS object to be created is first checked in + * {@link CMSAdapterVocabulary#CMS_OBJECT_NAME} assertion. If the resource has not this assertion, the + * name of the CMS object is set as the URI of the resource. + * <p> + * The location of the CMS object in the content repository is specified through the + * {@link CMSAdapterVocabulary#CMS_OBJECT_PATH} assertion. If the resource has not this assertion the path + * value is set with its name together with a preceding "/" character e.g "/"+name + * <p> + * Hierarchy between CMS object is set up by the {@link CMSAdapterVocabulary#CMS_OBJECT_PARENT_REF} + * assertions. CMS objects are started to be created from the root object and based on this assertions + * children are created. + * <p> * * @param session * This is a session object which is used to interact with JCR or CMIS repositories - * @param rootPath - * Content repository path in which root objects (e.g object represented by the URI - * <b>#TomHanks</b> in the above example) will be created * @param annotatedGraph * This {@link MGraph} object is an enhanced version of raw RDF data with "CMS vocabulary" - * annotations according to {@link RDFBridge}s. + * annotations + * @throws RDFBridgeException + */ + void storeRDFinRepository(Object session, MGraph annotatedGraph) throws RDFBridgeException; + + /** + * This method generates an RDF from the part specified with a path of the content repository. It + * transforms CMS objects into resources having {@link CMSAdapterVocabulary#CMS_OBJECT} rdf:type value. It + * also transforms properties and types of the CMS object into the RDF. Furthermore, parent assertions are + * added through the {@link CMSAdapterVocabulary#CMS_OBJECT_PARENT_REF}. + * + * @param session + * This is a session object which is used to interact with JCR or CMIS repositories + * @param rootPath + * Content repository path which is the root path indicating the root CMS object that will be + * transformed into RDF together with its children + * @return annotated {@link MGraph} * @throws RDFBridgeException */ - void storeRDFinRepository(Object session, String rootPath, MGraph annotatedGraph) throws RDFBridgeException; + MGraph generateRDFFromRepository(Object session, String rootPath) throws RDFBridgeException; + /** + * This method determines certain implementation of this interface is able to generate RDF from repository + * or update the repository based on the given RDF. + * + * @param connectionType + * connection type for which an {@link RDFMapper} is requested + * @return whether this implementation can handle specified connection type + */ + boolean canMap(String connectionType); }
