Author: alexdma
Date: Fri Feb  3 17:42:20 2012
New Revision: 1240259

URL: http://svn.apache.org/viewvc?rev=1240259&view=rev
Log:
STANBOL-482 : first commit of experimental content organizer code.

Added:
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/   (with props)
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/pom.xml
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubConnector.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubOrganizer.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Category.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Criterion.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentConnector.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentOrganizer.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentRetrievalException.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/util/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/util/ClerezzaBackendStatic.java
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/resources/
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/
    incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/java/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/java/org/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/java/org/apache/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/java/org/apache/stanbol/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/java/org/apache/stanbol/contentorganizer/
    
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/test/resources/

Propchange: incubator/stanbol/branches/ontonet-showcase/contentorganizer/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Feb  3 17:42:20 2012
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: incubator/stanbol/branches/ontonet-showcase/contentorganizer/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/pom.xml?rev=1240259&view=auto
==============================================================================
--- incubator/stanbol/branches/ontonet-showcase/contentorganizer/pom.xml (added)
+++ incubator/stanbol/branches/ontonet-showcase/contentorganizer/pom.xml Fri 
Feb  3 17:42:20 2012
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<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/maven-v4_0_0.xsd";>
+
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <groupId>org.apache.stanbol</groupId>
+               <artifactId>stanbol-parent</artifactId>
+               <version>0.9.0-incubating-SNAPSHOT</version>
+               <relativePath>.../../stanbol/parent</relativePath>
+       </parent>
+
+       <groupId>org.apache.stanbol</groupId>
+       <artifactId>org.apache.stanbol.contentorganizer</artifactId>
+       <packaging>bundle</packaging>
+
+       <name>Apache Stanbol Content Organizer</name>
+       <description>
+    A Stanbol application for categorising congent items. 
+    </description>
+
+       <inceptionYear>2012</inceptionYear>
+
+       <dependencies>
+
+               <!-- OSGi deps -->
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.compendium</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.felix</groupId>
+                       
<artifactId>org.apache.felix.scr.annotations</artifactId>
+               </dependency>
+
+               <!-- Stanbol deps -->
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.commons.stanboltools.datafileprovider</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.ontologymanager.ontonet</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.ontologymanager.registry</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       <artifactId>org.apache.stanbol.owl</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.reasoners.hermit</artifactId>
+                       <version>0.9.0-incubating-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.reasoners.manager</artifactId>
+                       <version>0.9.0-incubating-SNAPSHOT</version>
+               </dependency>
+
+               <!-- Testing deps -->
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+               </dependency>
+
+       </dependencies>
+
+       <build>
+               <plugins>
+
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               
<Data-Files>ontologies</Data-Files>
+                                               
<Data-Files-Priority>-100</Data-Files-Priority>
+                                               <Export-Package>
+                                                       
org.apache.stanbol.entitytranslator.*
+                                               </Export-Package>
+                                               <Import-Package>
+                                                       org.slf4j.*,
+                                                       *
+                                               </Import-Package>
+                                               <_nouses>true</_nouses>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <configuration>
+                                       <source>1.6</source>
+                                       <target>1.6</target>
+                               </configuration>
+                       </plugin>
+
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-scr-plugin</artifactId>
+                       </plugin>
+
+               </plugins>
+       </build>
+
+</project>

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubConnector.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubConnector.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubConnector.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubConnector.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,122 @@
+/*
+ * 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.stanbol.contentorganizer.impl;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.DC;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.stanbol.contenthub.servicesapi.search.SearchException;
+import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrSearch;
+import org.apache.stanbol.contenthub.servicesapi.store.Store;
+import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
+import 
org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary.SolrFieldName;
+import org.apache.stanbol.contentorganizer.servicesapi.ContentConnector;
+import 
org.apache.stanbol.contentorganizer.servicesapi.ContentRetrievalException;
+import org.apache.stanbol.contentorganizer.util.ClerezzaBackendStatic;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * @author alexdma
+ *
+ */
+public class ContentHubConnector implements ContentConnector {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Store contentStore;
+    private SolrSearch searchUtility;
+
+    public ContentHubConnector(Store contentStore, SolrSearch searchUtility) {
+        this.contentStore = contentStore;
+        this.searchUtility = searchUtility;
+    }
+
+    @Override
+    public Set<ContentItem> getContents() throws ContentRetrievalException {
+        Set<ContentItem> contents = new HashSet<ContentItem>();
+        try {
+            SolrDocumentList docs = searchUtility.search("*:*").getResults();
+
+            // TODO replace this wildcard Solr query once the Store provides 
listing methods.
+            for (SolrDocument doc : docs)
+                try {
+                    String id = (String) 
doc.getFieldValue(SolrFieldName.ID.toString());
+                    contents.add(contentStore.get(id));
+                } catch (Throwable t) {
+                    log.error("Failed to get content item from document " + doc
+                              + " . Continuing retrieval loop...", t);
+                    continue;
+                }
+
+            computeMetadata(docs);
+
+        } catch (SearchException e) {
+            throw new ContentRetrievalException(e);
+        }
+        return contents;
+    }
+
+    private void computeMetadata(Collection<SolrDocument> docs) {
+        for (SolrDocument doc : docs) {
+            String id = (String) 
doc.getFieldValue(SolrFieldName.ID.toString());
+            try {
+                ContentItem ci = contentStore.get(id);
+
+                String title = (String) 
doc.getFieldValue(SolrFieldName.TITLE.toString());
+
+                LockableMGraph mg = ci.getMetadata();
+                Lock writeLock = mg.getLock().writeLock();
+
+                Triple t = new TripleImpl(ci.getUri(), DC.title, 
ClerezzaBackendStatic.createLiteral(title,
+                    Locale.getDefault(), null));
+                writeLock.lock();
+                mg.add(t);
+                writeLock.unlock();
+
+                Object obj = doc.getFieldValue("authors_t");
+                if (obj != null && obj instanceof Collection<?>) {
+                    for (Object s : (Collection<?>) obj) {
+                        t = new TripleImpl(ci.getUri(), new 
UriRef("http://schema.org/author";), new UriRef(
+                                s.toString()));
+                        writeLock.lock();
+                        mg.add(t);
+                        writeLock.unlock();
+                    }
+                }
+
+            } catch (StoreException e) {
+                log.error("Must skip content item " + id, e);
+                continue;
+            }
+
+        }
+    }
+
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubOrganizer.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubOrganizer.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubOrganizer.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/impl/ContentHubOrganizer.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,205 @@
+/*
+ * 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.stanbol.contentorganizer.impl;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrSearch;
+import org.apache.stanbol.contenthub.servicesapi.store.Store;
+import org.apache.stanbol.contentorganizer.model.Category;
+import org.apache.stanbol.contentorganizer.model.Criterion;
+import org.apache.stanbol.contentorganizer.servicesapi.ContentConnector;
+import org.apache.stanbol.contentorganizer.servicesapi.ContentOrganizer;
+import 
org.apache.stanbol.contentorganizer.servicesapi.ContentRetrievalException;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.entityhub.servicesapi.Entityhub;
+import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteManager;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * @author alexdma
+ *
+ */
+@Component(immediate = true, metatype = false)
+@Service
+public class ContentHubOrganizer implements ContentOrganizer<Store> {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final static String DEFAULT_ROOT_PATH = 
"datafiles/contentorganizer";
+    private final static String DEFAULT_FOLDER_NAME = "metadata";
+
+    @Reference
+    protected Store contentStore;
+
+    @Reference
+    protected SolrSearch solrSearch;
+
+    @Reference
+    protected Entityhub entityHub;
+
+    @Reference
+    protected Serializer serializer;
+
+    @Reference
+    protected ReferencedSiteManager siteMgr;
+
+    private ContentConnector connector;
+
+    private File contentMetadataDir;
+
+    public ContentHubOrganizer() {
+        super();
+    }
+
+    public ContentHubOrganizer(Store contentStore,
+                               SolrSearch solrSearch,
+                               Dictionary<String,Object> configuration) {
+        this();
+        this.contentStore = contentStore;
+        this.solrSearch = solrSearch;
+        try {
+            activate(configuration);
+        } catch (IOException e) {
+            log.error("Unable to access component context.", e);
+        }
+    }
+
+    /**
+     * Used to configure an instance within an OSGi container.
+     * 
+     * @throws IOException
+     */
+    @SuppressWarnings("unchecked")
+    @Activate
+    protected void activate(ComponentContext context) throws IOException {
+        log.info("in " + ContentHubOrganizer.class + " activate with context " 
+ context);
+        if (context == null) {
+            throw new IllegalStateException("No valid" + 
ComponentContext.class + " parsed in activate!");
+        }
+
+        String slingHome = 
context.getBundleContext().getProperty("sling.home");
+        if (!slingHome.endsWith(File.separator)) slingHome += File.separator;
+        contentMetadataDir = new File(slingHome + DEFAULT_ROOT_PATH, 
DEFAULT_FOLDER_NAME);
+
+        // if directory for programs does not exist, create it
+        if (!contentMetadataDir.exists()) {
+            if (contentMetadataDir.mkdirs()) {
+                log.info("Directory for metadata created succesfully");
+            } else {
+                log.error("Directory for metadata COULD NOT be created");
+                throw new IOException("Directory : " + 
contentMetadataDir.getAbsolutePath()
+                                      + " cannot be created");
+            }
+        }
+
+        activate((Dictionary<String,Object>) context.getProperties());
+    }
+
+    /**
+     * Called within both OSGi and non-OSGi environments.
+     * 
+     * @param configuration
+     * @throws IOException
+     */
+    protected void activate(Dictionary<String,Object> configuration) throws 
IOException {
+
+        connector = new ContentHubConnector(contentStore, solrSearch);
+        classifyContent(contentStore);
+
+        log.debug(ContentHubOrganizer.class + " activated.");
+    }
+
+    @Deactivate
+    protected void deactivate(ComponentContext context) {
+        log.info("in " + ContentHubOrganizer.class + " deactivate with context 
" + context);
+
+        connector = null;
+
+        log.debug(ContentHubOrganizer.class + " deactivated.");
+    }
+
+    @Override
+    public Set<Criterion> getSuitableCriteria(Collection<ContentItem> 
contentItems) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Map<ContentItem,Set<Category>> classifyContent(Store contentStore) {
+
+        // Do stuff here for the time being...
+
+        Set<ContentItem> contents;
+        try {
+            contents = connector.getContents();
+        } catch (ContentRetrievalException e1) {
+            log.error("Failed to retrieve stored contents.", e1);
+            contents = Collections.emptySet();
+        }
+
+        MGraph mg = new SimpleMGraph();
+        for (ContentItem ci : contents)
+            mg.addAll(ci.getMetadata());
+
+        File f = null;
+        try {
+            f = new File(contentMetadataDir, "all.rdf");
+            serializer.serialize(new FileOutputStream(f), mg, 
SupportedFormat.RDF_XML);
+        } catch (UnsupportedFormatException e) {
+            log.error("Unsupported serialization format {} ! This should not 
happen...",
+                SupportedFormat.RDF_XML);
+        } catch (FileNotFoundException e) {
+            log.error("Could not obtain file {} for writing. ", f);
+        }
+
+        try {
+            f = new File(contentMetadataDir, "enhancement.rdf");
+            serializer.serialize(new FileOutputStream(f), 
contentStore.getEnhancementGraph(),
+                SupportedFormat.RDF_XML);
+        } catch (UnsupportedFormatException e) {
+            log.error("Unsupported serialization format {} ! This should not 
happen...",
+                SupportedFormat.RDF_XML);
+        } catch (FileNotFoundException e) {
+            log.error("Could not obtain file {} for writing. ", f);
+        }
+
+        return null;
+    }
+
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Category.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Category.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Category.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Category.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,26 @@
+/*
+ * 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.stanbol.contentorganizer.model;
+
+/**
+ * 
+ * @author alexdma
+ * 
+ */
+public interface Category {
+
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Criterion.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Criterion.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Criterion.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/model/Criterion.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,26 @@
+/*
+ * 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.stanbol.contentorganizer.model;
+
+/**
+ * 
+ * @author alexdma
+ *
+ */
+public interface Criterion {
+
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentConnector.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentConnector.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentConnector.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentConnector.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.stanbol.contentorganizer.servicesapi;
+
+import java.util.Set;
+
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+
+/**
+ * 
+ * @author alexdma
+ * 
+ */
+public interface ContentConnector {
+
+    Set<ContentItem> getContents() throws ContentRetrievalException;
+
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentOrganizer.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentOrganizer.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentOrganizer.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentOrganizer.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,39 @@
+/*
+ * 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.stanbol.contentorganizer.servicesapi;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.stanbol.contentorganizer.model.Category;
+import org.apache.stanbol.contentorganizer.model.Criterion;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+
+/**
+ * 
+ * @author alexdma
+ * 
+ * @param <S>
+ *            the content storage system.
+ */
+public interface ContentOrganizer<S> {
+
+    Set<Criterion> getSuitableCriteria(Collection<ContentItem> contentItems);
+
+    Map<ContentItem,Set<Category>> classifyContent(S contentStore);
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentRetrievalException.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentRetrievalException.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentRetrievalException.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/servicesapi/ContentRetrievalException.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.stanbol.contentorganizer.servicesapi;
+
+/**
+ * 
+ * @author alexdma
+ * 
+ */
+public class ContentRetrievalException extends Exception {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -6786939886951601329L;
+
+    public ContentRetrievalException() {
+        super();
+    }
+
+    public ContentRetrievalException(String message) {
+        super(message);
+    }
+
+    public ContentRetrievalException(String message, Throwable cause) {
+        super(message);
+        initCause(cause);
+    }
+
+    public ContentRetrievalException(Throwable cause) {
+        initCause(cause);
+    }
+
+}

Added: 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/util/ClerezzaBackendStatic.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/util/ClerezzaBackendStatic.java?rev=1240259&view=auto
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/util/ClerezzaBackendStatic.java
 (added)
+++ 
incubator/stanbol/branches/ontonet-showcase/contentorganizer/src/main/java/org/apache/stanbol/contentorganizer/util/ClerezzaBackendStatic.java
 Fri Feb  3 17:42:20 2012
@@ -0,0 +1,116 @@
+/*
+ * 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.stanbol.contentorganizer.util;
+
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Locale;
+
+import org.apache.clerezza.rdf.core.Language;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.util.W3CDateFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * @author alexdma,sinaci
+ * 
+ */
+public class ClerezzaBackendStatic {
+
+    private static final String XSD = "http://www.w3.org/2001/XMLSchema#";;
+    final private static String xsdInteger = xsd("integer");
+    final private static String xsdInt = xsd("int");
+    final private static String xsdShort = xsd("short");
+    final private static String xsdByte = xsd("byte");
+    final private static String xsdLong = xsd("long");
+    final private static String xsdDouble = xsd("double");
+    final private static String xsdFloat = xsd("float");
+    final private static String xsdAnyURI = xsd("anyURI");
+    final private static String xsdDateTime = xsd("dateTime");
+    final private static String xsdBoolean = xsd("boolean");
+    final private static String xsdString = xsd("string");
+
+    final private static String xsd(String name) {
+        return XSD + name;
+    }
+
+    private static final Logger log = 
LoggerFactory.getLogger(ClerezzaBackendStatic.class);
+
+    /*
+     * From ContentHub Clerezza backend.
+     */
+    public static Resource createLiteral(String content, Locale language, URI 
type) {
+        log.debug("creating literal with content \"{}\", language {}, datatype 
{}", new Object[] {content,
+                                                                               
                   language,
+                                                                               
                   type});
+        if (language == null && type == null) {
+            return createLiteral(content);
+        } else if (type == null) {
+            return new PlainLiteralImpl(content, new 
Language(language.getLanguage()));
+        } else {
+            return 
LiteralFactory.getInstance().createTypedLiteral(getTypedObject(content, 
type.toString()));
+        }
+    }
+
+    /*
+     * From ContentHub Clerezza backend.
+     */
+    public static Resource createLiteral(String content) {
+        log.debug("creating literal with content \"{}\"", content);
+        return LiteralFactory.getInstance().createTypedLiteral(content);
+    }
+
+    private static Object getTypedObject(String content, String type) {
+        Object obj = content;
+        if (type.toString().equals(xsdInteger)) {
+            obj = Integer.valueOf(content);
+        } else if (type.toString().equals(xsdInt)) {
+            obj = Integer.valueOf(content);
+        } else if (type.toString().equals(xsdShort)) {
+            obj = Integer.valueOf(content);
+        } else if (type.toString().equals(xsdByte)) {
+            obj = Integer.valueOf(content);
+        } else if (type.toString().equals(xsdLong)) {
+            obj = Long.valueOf(content);
+        } else if (type.toString().equals(xsdDouble)) {
+            obj = Double.valueOf(content);
+        } else if (type.toString().equals(xsdFloat)) {
+            obj = Float.valueOf(content);
+        } else if (type.toString().equals(xsdAnyURI)) {
+            obj = new UriRef(content);
+        } else if (type.toString().equals(xsdDateTime)) {
+            DateFormat dateFormat = new W3CDateFormat();
+            try {
+                obj = dateFormat.parse(content);
+            } catch (ParseException e) {
+                throw new IllegalArgumentException(e);
+            }
+        } else if (type.toString().equals(xsdBoolean)) {
+            obj = Boolean.valueOf(content);
+        } else if (type.toString().equals(xsdString)) {
+            obj = content;
+        }
+        return obj;
+    }
+
+}


Reply via email to