incubator-any23-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mosta...@apache.org
Subject svn commit: r1229627 [2/5] - in /incubator/any23/trunk: ./ any23-core/ any23-core/bin/ any23-core/src/main/java/org/deri/any23/ any23-core/src/main/java/org/deri/any23/cli/ any23-core/src/main/java/org/deri/any23/eval/ any23-core/src/main/java/org/deri...
Date Tue, 10 Jan 2012 16:32:33 GMT
Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdf/TriXExtractor.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdf/TriXExtractor.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdf/TriXExtractor.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdf/TriXExtractor.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
+ *
+ * Licensed 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.deri.any23.extractor.rdf;
+
+import org.deri.any23.extractor.ExtractionContext;
+import org.deri.any23.extractor.ExtractionResult;
+import org.deri.any23.extractor.ExtractorDescription;
+import org.deri.any23.extractor.ExtractorFactory;
+import org.deri.any23.extractor.SimpleExtractorFactory;
+import org.openrdf.rio.helpers.RDFParserBase;
+
+import java.util.Arrays;
+
+/**
+ * Concrete implementation of {@link ContentExtractor}
+ * to perform extraction on <a href="http://www.w3.org/2004/03/trix/">TriX</a> documents.
+ *
+ * @author Michele Mostarda (mostarda@fbk.eu)
+ */
+public class TriXExtractor extends BaseRDFExtractor {
+
+    public final static ExtractorFactory<TriXExtractor> factory =
+            SimpleExtractorFactory.create(
+                    "rdf-trix",
+                    null,
+                    Arrays.asList(
+                            "application/trix"
+                    ),
+                    "example-trix.trx",
+                    TriXExtractor.class
+            );
+
+    /**
+     * Constructor, allows to specify the validation and error handling policies.
+     *
+     * @param verifyDataType   if <code>true</code> the data types will be verified,
+     *                         if <code>false</code> will be ignored.
+     * @param stopAtFirstError if <code>true</code> the parser will stop at first parsing error,
+     *                         if <code>false</code> will ignore non blocking errors.
+     */
+    public TriXExtractor(boolean verifyDataType, boolean stopAtFirstError) {
+        super(verifyDataType, stopAtFirstError);
+    }
+
+    /**
+     * Default constructor, with no verification of data types and not stop at first error.
+     */
+    public TriXExtractor() {
+        this(true, true);
+    }
+
+    public ExtractorDescription getDescription() {
+        return factory;
+    }
+
+    @Override
+    protected RDFParserBase getParser(ExtractionContext extractionContext, ExtractionResult extractionResult) {
+        return RDFParserFactory.getInstance().getTriXParser(
+                isVerifyDataType(), isStopAtFirstError(), extractionContext, extractionResult
+        );
+    }
+
+
+}

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Extractor.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Extractor.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Extractor.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Extractor.java Tue Jan 10 16:32:28 2012
@@ -45,7 +45,7 @@ public class RDFa11Extractor implements 
                     NAME,
                     null,
                     Arrays.asList("text/html;q=0.3", "application/xhtml+xml;q=0.3"),
-                    null,
+                    "example-rdfa11.html",
                     RDFa11Extractor.class
             );
 

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Parser.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Parser.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Parser.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/extractor/rdfa/RDFa11Parser.java Tue Jan 10 16:32:28 2012
@@ -54,7 +54,7 @@ public class RDFa11Parser {
     private static final Logger logger = LoggerFactory.getLogger(RDFa11Parser.class);
 
     public static final String CURIE_SEPARATOR      = ":";
-    public static final String URI_PREFIX_SEPARATOR = ":";
+    public static final char   URI_PREFIX_SEPARATOR = ':';
     public static final String URI_SCHEMA_SEPARATOR = "://";
     public static final String URI_PATH_SEPARATOR   = "/";
 
@@ -113,8 +113,38 @@ public class RDFa11Parser {
         return documentURL;
     }
 
+    /**
+     * Given a prefix declaration returns a list of <code>prefixID:prefixURL</code> strings
+     * normalizing blanks where present.
+     *
+     * @param prefixesDeclaration
+     * @return
+     */
+    protected static String[] extractPrefixSections(String prefixesDeclaration) {
+        final String[] parts = prefixesDeclaration.split("\\s");
+        final List<String> out = new ArrayList<String>();
+        int i = 0;
+        while(i < parts.length) {
+            final String part = parts[i];
+            if(part.length() == 0) {
+                i++;
+                continue;
+            }
+            if(part.charAt( part.length() -1 ) == URI_PREFIX_SEPARATOR) {
+                i++;
+                while(i < parts.length && parts[i].length() == 0) i++;
+                out.add( part + (i < parts.length ? parts[i] : "") );
+                i++;
+            } else {
+                out.add(parts[i]);
+                i++;
+            }
+        }
+        return out.toArray( new String[out.size()] );
+    }
+
     protected static boolean isAbsoluteURI(String uri) {
-        return uri.indexOf(URI_SCHEMA_SEPARATOR) != -1;
+        return uri.contains(URI_SCHEMA_SEPARATOR);
     }
 
     protected static boolean isCURIE(String curie) {
@@ -640,7 +670,7 @@ public class RDFa11Parser {
     private void extractPrefixes(Node node, List<PrefixMap> prefixMapList) {
         final String prefixAttribute = DomUtils.readAttribute(node, PREFIX_ATTRIBUTE, null);
         if(prefixAttribute == null) return;
-        final String[] prefixParts = prefixAttribute.split("\\s");
+        final String[] prefixParts = extractPrefixSections(prefixAttribute);
         for(String prefixPart : prefixParts) {
             int splitPoint = prefixPart.indexOf(URI_PREFIX_SEPARATOR);
             final String prefix = prefixPart.substring(0, splitPoint);
@@ -883,8 +913,8 @@ public class RDFa11Parser {
             mapping = mapping.substring(1);
         }
 
-        final String[] parts = mapping.split(":");
-        if(parts.length != 2) { // there is no prefix separator.
+        final int prefixSeparatorIndex = mapping.indexOf(':');
+        if(prefixSeparatorIndex == -1) { // there is no prefix separator.
             if(resolutionPolicy == ResolutionPolicy.NSRequired) {
                 throw new IllegalArgumentException(
                         String.format("Invalid mapping string [%s], must declare a prefix.", mapping)
@@ -900,11 +930,12 @@ public class RDFa11Parser {
             return resolveURI(documentBase.toString() + mapping);
         }
 
-        final URI curieMapping = getMapping(parts[0]);
+        final String prefix = mapping.substring(0, prefixSeparatorIndex);
+        final URI curieMapping = getMapping(prefix);
         if(curieMapping == null) {
-            throw new IllegalArgumentException( String.format("Cannot map prefix '%s'", parts[0]) );
+            throw new IllegalArgumentException( String.format("Cannot map prefix '%s'", prefix) );
         }
-        final String candidateCURIEStr = curieMapping.toString() + parts[1];
+        final String candidateCURIEStr = curieMapping.toString() + mapping.substring(prefixSeparatorIndex + 1);
         final java.net.URI candidateCURIE;
         try {
             candidateCURIE = new java.net.URI(candidateCURIEStr);

Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuads.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuads.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuads.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuads.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,39 @@
+/**
+ * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
+ *
+ * Licensed 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.deri.any23.io.nquads;
+
+import org.openrdf.rio.RDFFormat;
+
+import java.nio.charset.Charset;
+
+/**
+ * Defines the <i>N-Quads</i> format.
+ *
+ * @author Michele Mostarda (mostarda@fbk.eu)
+ */
+public class NQuads {
+
+    /**
+     * Returns the format associate to the <i>NQuads</i> specification.
+     */
+    public static RDFFormat FORMAT =
+               RDFFormat.register("N-Quads", "text/nquads", "nq", Charset.forName("UTF-8"));
+
+    private NQuads(){}
+
+}

Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsParser.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsParser.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsParser.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsParser.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,697 @@
+/**
+ * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
+ *
+ * Licensed 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.deri.any23.io.nquads;
+
+import org.deri.any23.util.ReaderInputStream;
+import org.openrdf.model.BNode;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.datatypes.XMLDatatypeUtil;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.rio.ParseLocationListener;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFHandler;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.rio.helpers.RDFParserBase;
+import org.openrdf.rio.ntriples.NTriplesUtil;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+/**
+ * <i>N-Quads</i> parser implementation based on the
+ * {@link org.openrdf.rio.RDFParser} interface.
+ * See the format specification <a href="http://sw.deri.org/2008/07/n-quads/">here</a>.
+ *
+ * @author Michele Mostarda (mostarda@fbk.eu)
+ * @see org.openrdf.rio.RDFParser
+ */
+public class NQuadsParser extends RDFParserBase {
+
+    /**
+     * Location listener acquired when parsing started.
+     */
+    private ParseLocationListener locationListener;
+
+    /**
+     * RDF handler acquired when parsing started.
+     */
+    private RDFHandler rdfHandler;
+
+    /**
+     * Current row, col and marker trackers.
+     */
+    private int row, col, mark;
+
+    public NQuadsParser() {}
+
+    public RDFFormat getRDFFormat() {
+        return NQuads.FORMAT;
+    }
+
+    public void parse(Reader reader, String s)
+    throws IOException, RDFParseException, RDFHandlerException {
+        ReaderInputStream readerInputStream = new ReaderInputStream(reader);
+        parse(readerInputStream, s);
+    }
+
+    public synchronized void parse(InputStream is, String baseURI)
+    throws IOException, RDFParseException, RDFHandlerException {
+        if(is == null) {
+            throw new NullPointerException("inputStream cannot be null.");
+        }
+        if(baseURI == null) {
+            throw new NullPointerException("baseURI cannot be null.");
+        }
+
+        try {
+            row = col = 1;
+
+            locationListener = getParseLocationListener();
+            rdfHandler = getRDFHandler();
+
+            setBaseURI(baseURI);
+
+            final BufferedReader br = new BufferedReader( new InputStreamReader(is) );
+            if( rdfHandler != null ) {
+                rdfHandler.startRDF();
+            }
+            while( parseLine(br) ) {
+                nextRow();
+            }
+        } finally {
+            if(rdfHandler != null) {
+                rdfHandler.endRDF();
+            }
+            clear();
+            clearBNodeIDMap();
+        }
+    }
+
+    /**
+     * Moves to the next row, resets the column.
+     */
+    private void nextRow() {
+        col = 0;
+        row++;
+        if(locationListener != null) {
+            locationListener.parseLocationUpdate(row, col);
+        }
+    }
+
+    /**
+     * Moves to the next column.
+     */
+    private void nextCol() {
+        col++;
+        if(locationListener != null) {
+            locationListener.parseLocationUpdate(row, col);
+        }
+    }
+
+    /**
+     * Reads the next char.
+     *
+     * @param br
+     * @return the next read char.
+     * @throws IOException
+     */
+    private char readChar(BufferedReader br) throws IOException {
+        final int c = br.read();
+        if(c == -1) {
+            throw new EOS();
+        }
+        nextCol();
+        return (char) c;
+    }
+
+    /**
+     * Reads an unicode char with pattern <code>\\uABCD</code>.
+     *
+     * @param br input reader.
+     * @return read char.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private char readUnicode(BufferedReader br) throws IOException, RDFParseException {
+        final char[] unicodeSequence = new char[4];
+        for(int i = 0; i < unicodeSequence.length; i++) {
+            unicodeSequence[i] = readChar(br);
+        }
+        final String unicodeCharStr = new String(unicodeSequence);
+        try {
+            return (char) Integer.parseInt(unicodeCharStr, 16);
+        } catch (NumberFormatException nfe) {
+            reportError("Error while converting unicode char '\\u" + unicodeCharStr + "'", row, col);
+            throw new IllegalStateException();
+        }
+    }
+
+    /**
+     * Marks the buffered input stream with the current location.
+     *
+     * @param br
+     */
+    private void mark(BufferedReader br) throws IOException {
+        mark = col;
+        br.mark(5);
+    }
+
+    /**
+     * Resets the buffered input stream and update the new location.
+     *
+     * @param br
+     * @throws IOException
+     */
+    private void reset(BufferedReader br) throws IOException {
+        col = mark;
+        br.reset();
+        if(locationListener != null) {
+            locationListener.parseLocationUpdate(row, col);
+        }
+    }
+
+    /**
+     * Asserts to read a specific char.
+     *
+     * @param br
+     * @param c
+     * @throws IOException
+     */
+    private void assertChar(BufferedReader br, char c) throws IOException {
+        if( readChar(br) != c) {
+            throw new IllegalArgumentException(
+                    String.format("Unexpected char at location %s %s, expected '%s'", row, col, c)
+            );
+        }
+    }
+
+    /**
+     * Parsers an <i>NQuads</i> line.
+     *
+     * @param br input stream reader containing NQuads.
+     * @return <code>false</code> if the parsing completed, <code>true</code> otherwise.
+     * @throws IOException
+     * @throws RDFParseException
+     * @throws RDFHandlerException
+     */
+    private boolean parseLine(BufferedReader br)
+    throws IOException, RDFParseException, RDFHandlerException {
+
+        if(!consumeSpacesAndNotEOS(br)) {
+            return false;
+        }
+
+        // Consumes empty line or line comment.
+        try {
+            if(consumeEmptyLine(br)) return true;
+            if( consumeComment(br) ) return true;
+        } catch (EOS eos) {
+            return false;
+        }
+
+        final Resource sub;
+        final URI      pred;
+        final Value    obj;
+        final URI      graph;
+        try {
+            sub = parseSubject(br);
+            consumeSpaces(br);
+            pred = parsePredicate(br);
+            consumeSpaces(br);
+            obj = parseObject(br);
+            consumeSpaces(br);
+            graph = parseGraph(br);
+            consumeSpaces(br);
+            parseDot(br);
+        } catch (EOS eos) {
+            reportFatalError("Unexpected end of line.", row, col);
+            throw new IllegalStateException();
+        }
+
+        notifyStatement(sub, pred, obj, graph);
+
+        if(!consumeSpacesAndNotEOS(br)) {
+            return false;
+        }
+        return readChar(br) == '\n';
+    }
+
+    /**
+     * Consumes the line if empty (contains just a carriage return).
+     *
+     * @param br input NQuads stream.
+     * @return <code>true</code> if the line is empty.
+     * @throws IOException if an error occurs while consuming stream.
+     */
+    private boolean consumeEmptyLine(BufferedReader br) throws IOException {
+        char c;
+        mark(br);
+        c = readChar(br);
+        if (c == '\n') {
+            return true;
+        } else {
+            reset(br);
+            return false;
+        }
+    }
+
+    /**
+     * Consumes all subsequent spaces and returns true, if End Of Stream is reached instead returns false.
+     * @param br input NQuads stream reader.
+     * @return <code>true</code> if there are other chars to be consumed.
+     * @throws IOException if an error occurs while consuming stream.
+     */
+    private boolean consumeSpacesAndNotEOS(BufferedReader br) throws IOException {
+        try {
+            consumeSpaces(br);
+            return true;
+        } catch (EOS eos) {
+            return false;
+        }
+    }
+
+    /**
+     * Consumes a comment if any.
+     *
+     * @param br input NQuads stream reader.
+     * @return <code>true</code> if comment has been consumed, false otherwise.
+     * @throws IOException
+     */
+    private boolean consumeComment(BufferedReader br) throws IOException {
+        char c;
+        mark(br);
+        c = readChar(br);
+        if (c == '#') {
+            mark(br);
+            while (readChar(br) != '\n');
+            mark(br);
+            return true;
+        } else {
+            reset(br);
+            return false;
+        }
+    }
+
+    /**
+     * Notifies the parsed statement to the {@link RDFHandler}.
+     *
+     * @param sub
+     * @param pred
+     * @param obj
+     * @param graph
+     * @throws RDFParseException
+     * @throws RDFHandlerException
+     */
+    private void notifyStatement(Resource sub, URI pred, Value obj, URI graph)
+    throws RDFParseException, RDFHandlerException {
+        Statement statement = createStatement(sub, pred, obj, graph);
+        if (rdfHandler != null) {
+            try {
+                rdfHandler.handleStatement(statement);
+            } catch (RDFHandlerException rdfhe) {
+                reportFatalError(rdfhe);
+                throw rdfhe;
+            }
+        }
+    }
+
+    /**
+     * Consumes spaces until a non space char is detected.
+     *
+     * @param br input stream reader from which consume spaces.
+     * @throws IOException
+     */
+    private void consumeSpaces(BufferedReader br) throws IOException {
+        char c;
+        while(true) {
+            mark(br);
+            c = readChar(br);
+            if(c == ' ' || c == '\r' || c == '\f' || c == '\t') {
+                mark(br);
+            } else {
+                break;
+            }
+        }
+        reset(br);
+    }
+
+    /**
+     * Consumes the dot at the end of NQuads line.
+     *
+     * @param br
+     * @throws IOException
+     */
+    private void parseDot(BufferedReader br) throws IOException {
+        assertChar(br, '.');
+    }
+
+    /**
+     * Parses a URI enclosed within &lt; and &gt; brackets.
+     * @param br
+     * @return the parsed URI.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private URI parseURI(BufferedReader br) throws IOException, RDFParseException {
+        assertChar(br, '<');
+
+        StringBuilder sb = new StringBuilder();
+        char c;
+        while(true) {
+            c = readChar(br);
+            if(c != '>') {
+                sb.append(c);
+            } else {
+                break;
+            }
+        }
+        mark(br);
+
+        try {
+            // TODO - LOW: used to unescape \\uXXXX unicode chars. Unify with #printEscaped().
+            String uriStr = NTriplesUtil.unescapeString( sb.toString() );
+            URI uri;
+            if(uriStr.charAt(0) == '#') {
+                uri = resolveURI(uriStr);
+            } else {
+                uri = createURI(uriStr);
+            }
+            return uri;
+        } catch (RDFParseException rdfpe) {
+            reportFatalError(rdfpe, row, col);
+            throw rdfpe;
+        }
+    }
+
+    /**
+     * Parses a BNode.
+     *
+     * @param br the buffered input stream.
+     * @return the generated bnode.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private BNode parseBNode(BufferedReader br) throws IOException, RDFParseException {
+        assertChar(br, '_');
+        assertChar(br, ':');
+
+        char c;
+        StringBuilder sb = new StringBuilder();
+        while(true) {
+            c = readChar(br);
+            if(c != ' ' && c != '<') {
+                sb.append(c);
+                mark(br);
+            } else {
+                break;
+            }
+        }
+        reset(br);
+
+        try {
+            return createBNode( sb.toString() );
+        } catch (RDFParseException rdfpe) {
+            reportFatalError(rdfpe, row, col);
+            throw rdfpe;
+        }
+    }
+
+    /**
+     * Parses a literal attribute that can be either the language or the data type.
+     *
+     * @param br
+     * @return the literal attribute.
+     * @throws IOException
+     */
+    private LiteralAttribute parseLiteralAttribute(BufferedReader br) throws IOException {
+        char c = readChar(br);
+        if(c != '^' && c != '@') {
+            reset(br);
+            return null;
+        }
+
+        boolean isLang = true;
+        if(c == '^') {
+            isLang = false;
+            assertChar(br, '^');
+        }
+
+        // Consuming eventual open URI.
+        mark(br);
+        c = readChar(br);
+        if(c != '<') {
+            reset(br);
+        }
+
+        StringBuilder sb = new StringBuilder();
+        while(true) {
+            c = readChar(br);
+            if(c == '>') {
+                mark(br);
+                continue;
+            }
+            if(c != ' ' && c != '<') {
+                mark(br);
+                sb.append(c);
+            } else {
+                break;
+            }
+        }
+        reset(br);
+        return new LiteralAttribute( isLang, sb.toString() );
+    }
+
+    /**
+     * Validates and normalize the value of a literal on the basis of the datat ype handling policy and
+     * the associated data type.
+     *
+     * @param value
+     * @param datatype
+     * @return the normalized data type. It depends on the data type handling policy and the specified data type.
+     * @throws RDFParseException
+     */
+    private String validateAndNormalizeLiteral(String value, URI datatype) throws RDFParseException {
+        DatatypeHandling dh = datatypeHandling();
+        if(dh.equals( DatatypeHandling.IGNORE )) {
+            return value;
+        }
+
+        if ( dh.equals(DatatypeHandling.VERIFY) ) {
+            if( ! XMLDatatypeUtil.isBuiltInDatatype(datatype)){
+                return value;
+            }
+            if( ! XMLDatatypeUtil.isValidValue(value, datatype) ) {
+                throw new RDFParseException(
+                        String.format("Illegal literal value '%s' with datatype %s", value, datatype.stringValue() ),
+                        row, col
+                );
+            }
+            return value;
+        } else if( dh.equals(DatatypeHandling.NORMALIZE) ) {
+            return XMLDatatypeUtil.normalize(value, datatype);
+        } else {
+            throw new IllegalArgumentException( String.format("Unsupported datatype handling: %s", dh) );
+        }
+    }
+
+    /**
+     * Prints the escaped version of the given char c.
+     *
+     * @param c escaped char.
+     * @param sb output string builder.
+     */
+    private void printEscaped(char c, StringBuilder sb) {
+        if(c == 'b') {
+            sb.append('\b');
+            return;
+        }
+        if(c == 'f') {
+            sb.append('\f');
+            return;
+        }
+        if(c == 'n') {
+            sb.append('\n');
+            return;
+        }
+        if(c == 'r') {
+            sb.append('\r');
+            return;
+        }
+        if(c == 't') {
+            sb.append('\t');
+            return;
+        }
+    }
+
+    /**
+     * Parses a literal.
+     *
+     * @param br
+     * @return the parsed literal.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private Value parseLiteral(BufferedReader br) throws IOException, RDFParseException {
+        assertChar(br, '"');
+
+        char c;
+        boolean escaped = false;
+        StringBuilder sb = new StringBuilder();
+        while(true) {
+            c = readChar(br);
+            if( c == '\\' ) {
+                if(escaped) {
+                    escaped = false;
+                    sb.append(c);
+                } else {
+                    escaped = true;
+                }
+                continue;
+            } else if(c == '"' && !escaped) {
+                break;
+            }
+            if(escaped) {
+                if(c == 'u') {
+                    char unicodeChar = readUnicode(br);
+                    sb.append(unicodeChar);
+                } else {
+                    printEscaped(c, sb);
+                }
+                escaped = false;
+            } else {
+                sb.append(c);
+            }
+        }
+        mark(br);
+
+        LiteralAttribute lt = parseLiteralAttribute(br);
+
+        final String value = sb.toString();
+        if(lt == null) {
+            return createLiteral(value, null, null);
+        }else if(lt.isLang) {
+            return createLiteral(
+                    value,
+                    lt.value,
+                    null
+            );
+        } else {
+            URI literalType = null;
+            try {
+                literalType = new URIImpl(lt.value);
+            } catch (Exception e) {
+                reportError( String.format("Error while parsing literal type '%s'", lt.value), row, col );
+            }
+            return createLiteral(
+                    validateAndNormalizeLiteral(value, literalType),
+                    null,
+                    literalType
+            );
+        }
+    }
+
+    /**
+     * Parses the subject sequence.
+     *
+     * @param br
+     * @return the corresponding URI object.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private Resource parseSubject(BufferedReader br) throws IOException, RDFParseException {
+        mark(br);
+        char c = readChar(br);
+        reset(br);
+        if( c == '<' ) {
+            return parseURI(br);
+        } else {
+            return parseBNode(br);
+        }
+    }
+
+    /**
+     * Parses the predicate URI.
+     *
+     * @param br
+     * @return the corresponding URI object.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private URI parsePredicate(BufferedReader br) throws IOException, RDFParseException {
+        return parseURI(br);
+    }
+
+    /**
+     * Parses the the object sequence.
+     *
+     * @param br
+     * @return the corresponding URI object.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private Value parseObject(BufferedReader br) throws IOException, RDFParseException {
+        mark(br);
+        char c = readChar(br);
+        reset(br);
+        if( c == '<' ) {
+            return parseURI(br);
+        } else if( c == '_') {
+            return parseBNode(br);
+        } else {
+            return parseLiteral(br);
+        }
+    }
+
+    /**
+     * Represents a literal with its attribute value that can be either a language or a data type.
+     */
+    class LiteralAttribute {
+        final boolean isLang;
+        final String value;
+
+        LiteralAttribute(boolean lang, String value) {
+            isLang = lang;
+            this.value = value;
+        }
+    }
+
+    /**
+     * Parses the graph URI.
+     *
+     * @param br
+     * @return the corresponding URI object.
+     * @throws IOException
+     * @throws RDFParseException
+     */
+    private URI parseGraph(BufferedReader br) throws IOException, RDFParseException {
+        return parseURI(br);
+    }
+
+    /**
+     * Defines the End Of Stream exception.
+     */
+    class EOS extends IOException {}
+
+}

Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsWriter.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsWriter.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsWriter.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/NQuadsWriter.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,273 @@
+/**
+ * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
+ *
+ * Licensed 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.deri.any23.io.nquads;
+
+import org.openrdf.model.BNode;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.rio.RDFWriter;
+import org.openrdf.rio.ntriples.NTriplesUtil;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <i>N-Quads</i> implementation of an {@link org.openrdf.rio.RDFWriter}.
+ * See the format specification <a href="http://sw.deri.org/2008/07/n-quads/">here</a>.
+ *
+ * @author Michele Mostarda (mostarda@fbk.eu)
+ */
+public class NQuadsWriter implements RDFWriter {
+
+    /**
+     * The table maintaining namespaces.
+     */
+    private Map<String,String> namespaceTable;
+
+    /**
+     * The output writer.
+     */
+    private Writer writer;
+
+    /**
+     * Maintain the started status.
+     */
+    private boolean started = false;
+
+    public NQuadsWriter(OutputStream os) {
+        this( new OutputStreamWriter(os) );
+    }
+
+    public NQuadsWriter(Writer w) {
+        if(w == null) {
+            throw new NullPointerException("the writer cannot be null.");
+        }
+        writer = w;
+    }
+
+    public RDFFormat getRDFFormat() {
+        return NQuads.FORMAT;
+    }
+
+    public void startRDF() throws RDFHandlerException {
+        if(started) {
+            throw new IllegalStateException("Parsing already started.");
+        }
+        started = true;
+    }
+
+    public void endRDF() throws RDFHandlerException {
+        if(!started) {
+            throw new IllegalStateException("Parsing never started.");
+        }
+
+        try {
+            writer.flush();
+        } catch (IOException ioe) {
+            throw new RDFHandlerException("Error while flushing writer.", ioe);
+        } finally {
+            started = false;
+            if(namespaceTable != null) {
+                namespaceTable.clear();
+            }
+        }
+    }
+
+    public void handleNamespace(String ns, String uri) throws RDFHandlerException {
+        if(!started) {
+            throw new IllegalStateException("Parsing never started.");
+        }
+
+        if(namespaceTable == null) {
+            namespaceTable = new HashMap<String, String>();
+        }
+        namespaceTable.put(ns, NTriplesUtil.escapeString(uri) );
+    }
+
+    public void handleStatement(Statement statement) throws RDFHandlerException {
+        if(!started) {
+            throw new IllegalStateException("Cannot handle statement without start parsing first.");
+        }
+
+        try {
+            printSubject(statement);
+            printSpace();
+            printPredicate(statement);
+            printSpace();
+            printObject(statement);
+            printSpace();
+            printGraph(statement);
+            printCloseStatement();
+        } catch (IOException ioe) {
+            throw new RDFHandlerException("An error occurred while printing statement.", ioe);
+        }
+    }
+
+    public void handleComment(String comment) throws RDFHandlerException {
+        try {
+            writer.write("# ");
+            writer.write(comment);
+            writer.append('\n');
+        } catch (IOException ioe) {
+            throw new RDFHandlerException("An error occurred while printing comment.", ioe);
+        }
+    }
+
+    /**
+     * Prints out a space.
+     *
+     * @throws IOException
+     */
+    private void printSpace() throws IOException {
+        writer.append(' ');
+    }
+
+    /**
+     * Prints out the close statement.
+     * 
+     * @throws IOException
+     */
+    private void printCloseStatement() throws IOException {
+        writer.append(" .\n");
+    }
+
+    /**
+     * Prints out a URI string, replacing the existing prefix if found.
+     * 
+     * @param uri the URI to print.
+     * @throws IOException
+     */
+    private void printURI(URI uri) throws IOException {
+        final String uriString = uri.stringValue();
+        int splitIdx = 0;
+        String namespace = null;
+        if(namespaceTable != null) {
+            splitIdx = uriString.indexOf(':');
+            if (splitIdx > 0) {
+                String prefix = uriString.substring(0, splitIdx);
+                namespace = namespaceTable.get(prefix);
+            }
+        }
+
+        if (namespace != null) {
+            writer.append('<');
+            writer.append(namespace);
+            writer.append( NTriplesUtil.escapeString(uriString.substring(splitIdx)) );
+            writer.append('>');
+        } else {
+            writer.append('<');
+            writer.append( NTriplesUtil.escapeString(uriString) );
+            writer.append('>');
+        }
+    }
+
+    /**
+     * Prints out the bnode.
+     *
+     * @param b bnode value.
+     * @throws IOException
+     */
+    private void printBNode(BNode b) throws IOException {
+        writer.append( NTriplesUtil.toNTriplesString(b) );
+    }
+
+    /**
+     * Prints out the resource.
+     *
+     * @param r resource value.
+     * @throws java.io.IOException
+     */
+    private void printResource(Resource r) throws IOException {
+        if(r instanceof BNode) {
+            printBNode((BNode) r);
+        } else if(r instanceof URI) {
+            printURI((URI) r);
+        } else {
+            throw new IllegalStateException();
+        }
+    }
+
+    /**
+     * Prints out a literal value.
+     *
+     * @param l literal value.
+     * @throws java.io.IOException
+     */
+    private void printLiteral(Literal l) throws IOException {
+        writer.append( NTriplesUtil.toNTriplesString(l) );
+    }
+
+    /**
+     * Prints out the subject.
+     * 
+     * @param s
+     * @throws IOException
+     */
+    private void printSubject(Statement s) throws IOException {
+        printResource( s.getSubject() );
+    }
+
+    /**
+     * Prints out the predicate.
+     *
+     * @param s
+     * @throws IOException
+     */
+    private void printPredicate(Statement s) throws IOException {
+        printURI( s.getPredicate() );
+    }
+
+    /**
+     * Prints out the object, handling all the logic to manage
+     * the literal data type / language attribute.
+     *
+     * @param s
+     * @throws IOException
+     */
+    private void printObject(Statement s) throws IOException {
+        Value v = s.getObject();
+        if(v instanceof Resource) {
+            printResource((Resource) v);
+            return;
+        }
+        printLiteral( (Literal) v );
+    }
+
+    /**
+     * Prints out the graph.
+     *
+     * @param s
+     * @throws IOException
+     */
+    private void printGraph(Statement s) throws IOException {
+        Resource graph = s.getContext();
+        if(graph != null) {
+            printResource( s.getContext() );
+        }
+    }
+
+}

Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/package-info.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/package-info.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/package-info.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/io/nquads/package-info.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,6 @@
+
+/**
+ * This package contains an <i>NQuads</i>
+ * parser and writer based on the <i>Sesame API</i>.
+ */
+package org.deri.any23.io.nquads;
\ No newline at end of file

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/mime/TikaMIMETypeDetector.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/mime/TikaMIMETypeDetector.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/mime/TikaMIMETypeDetector.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/mime/TikaMIMETypeDetector.java Tue Jan 10 16:32:28 2012
@@ -139,10 +139,6 @@ public class TikaMIMETypeDetector implem
         return CSVReaderBuilder.isCSV(is);
     }
 
-    public static void main(String[] args) {
-        new TikaMIMETypeDetector(new WhiteSpacesPurifier());
-    }
-
     /**
      * Tries to apply one of the given patterns on a sample of the input stream.
      *
@@ -225,6 +221,10 @@ public class TikaMIMETypeDetector implem
         }
     }
 
+    public TikaMIMETypeDetector() {
+        this( new WhiteSpacesPurifier() );
+    }
+
     /**
      * Estimates the <code>MIME</code> type of the content of input file.
      * The <i>input</i> stream must be resettable.

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/plugin/Any23PluginManager.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/plugin/Any23PluginManager.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/plugin/Any23PluginManager.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/plugin/Any23PluginManager.java Tue Jan 10 16:32:28 2012
@@ -32,6 +32,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -234,7 +235,7 @@ public class Any23PluginManager {
                 errors.add(t);
             }
         }
-        return errors.toArray( new Throwable[errors.size()] );
+        return errors.toArray(new Throwable[errors.size()]);
     }
 
     /**
@@ -251,12 +252,12 @@ public class Any23PluginManager {
     public synchronized <T> Set<Class<T>> getClassesInPackage(final String packageName, final ClassFilter filter)
     throws IOException {
         final Set<Class<T>> result = new HashSet<Class<T>>();
-        getClassesInPackageFromClasspath(packageName, filter, result);
+        loadClassesInPackageFromClasspath(packageName, filter, result);
         for(File jar : dynamicClassLoader.jars) {
-            getClassesInPackageFromJAR(jar, packageName, filter, result);
+            loadClassesInPackageFromJAR(jar, packageName, filter, result);
         }
         for(File dir : dynamicClassLoader.dirs) {
-            getClassesInPackageFromDir(dir, packageName, filter, result);
+            loadClassesInPackageFromDir(dir, packageName, filter, result);
         }
         return result;
     }
@@ -402,7 +403,7 @@ public class Any23PluginManager {
      * @param result list for writing result.
      * @throws java.io.IOException
      */
-    protected <T> void getClassesInPackageFromJAR(
+    protected <T> void loadClassesInPackageFromJAR(
             File jarFile,
             String packageName,
             ClassFilter filter,
@@ -448,7 +449,7 @@ public class Any23PluginManager {
      * @param <T> class types.
      * @throws MalformedURLException
      */
-    protected <T> void getClassesInPackageFromDir(
+    protected <T> void loadClassesInPackageFromDir(
             File classDir,
             final String packageName,
             final ClassFilter filter,
@@ -504,25 +505,50 @@ public class Any23PluginManager {
      * @param <T>
      * @throws IOException
      */
-    protected <T> void getClassesInPackageFromClasspath(
+    protected <T> void loadClassesInPackageFromClasspath(
             final String packageName,
             final ClassFilter filter,
             Set<Class<T>> result
     ) throws IOException {
-        final File codePath = new File(
-                this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
-        );
-        if (codePath.isDirectory()) {
-            getClassesInPackageFromDir(codePath, packageName, filter, result);
-        } else {
-            getClassesInPackageFromJAR(codePath, packageName, filter, result);
+        final String[] classpathEntries = getClasspathEntries();
+        for (String classPathEntry : classpathEntries) {
+            if(classPathEntry.trim().length() == 0) continue;
+            final File codePath = new File(URLDecoder.decode(classPathEntry, "UTF-8"));
+            if (codePath.isDirectory()) {
+                loadClassesInPackageFromDir(codePath, packageName, filter, result);
+            } else {
+                loadClassesInPackageFromJAR(codePath, packageName, filter, result);
+            }
         }
     }
 
+    /**
+     * @return the classpath entries.
+     */
+    private String[] getClasspathEntries() {
+        final String classpath          = System.getProperty("java.class.path");
+        assert classpath != null : "Class path is null.";
+        final String classpathSeparator = System.getProperty("path.separator");
+        assert classpathSeparator != null : "Class path separator is null.";
+        return classpath.split("\\" + classpathSeparator);
+    }
+
+    /**
+     * Checks if the class name is valid.
+     *
+     * @param clazzName
+     * @return
+     */
     private boolean isValidClassName(String clazzName) {
         return clazzName.endsWith(".class") && ! clazzName.contains("$");
     }
 
+    /**
+     * Converts a column separated list of dirs in a list of files.
+     *
+     * @param pluginDirsList
+     * @return
+     */
     private File[] getPluginLocations(String pluginDirsList) {
         final String[] locationsStr = pluginDirsList.split(PLUGIN_DIRS_LIST_SEPARATOR);
         final List<File> locations = new ArrayList<File>();

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/rdf/RDFUtils.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/rdf/RDFUtils.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/rdf/RDFUtils.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/rdf/RDFUtils.java Tue Jan 10 16:32:28 2012
@@ -16,7 +16,7 @@
 
 package org.deri.any23.rdf;
 
-import org.deri.any23.parser.NQuadsParser;
+import org.deri.any23.io.nquads.NQuadsParser;
 import org.deri.any23.util.MathUtils;
 import org.openrdf.model.BNode;
 import org.openrdf.model.Literal;

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/FileUtils.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/FileUtils.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/FileUtils.java Tue Jan 10 16:32:28 2012
@@ -166,11 +166,11 @@ public class FileUtils {
     }
 
     /**
-     * Reads the content of a file and return it in a string.
+     * Returns the content of a file a single string.
      *
      * @param f the file to read.
      * @return the content of file.
-     * @throws IOException if an exception occurs while locating or accessing the file.
+     * @throws IOException if an error occurs while locating or accessing the file.
      */
     public static String readFileContent(File f) throws IOException {
         FileInputStream fis = new FileInputStream(f);
@@ -178,6 +178,18 @@ public class FileUtils {
     }
 
     /**
+     * Returns all the lines of a file.
+     *
+     * @param f the file to read.
+     * @return a not <code>null</code> array with not <code>null</code> line strings.
+     * @throws IOException if an error occurs while locating or accessing the file.
+     */
+    public static String[] readFileLines(File f) throws IOException {
+        FileInputStream fis = new FileInputStream(f);
+        return StreamUtils.asLines(fis);
+    }
+
+    /**
      * Lists the content of a dir applying the specified filter.
      *
      * @param dir directory root.

Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/LogUtils.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/LogUtils.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/LogUtils.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/LogUtils.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
+ *
+ * Licensed 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.deri.any23.util;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Provides specific application logger configuration methods.
+ */
+public class LogUtils {
+
+    public static void setDefaultLogging() {
+        Logger.getLogger("").setLevel(Level.WARNING);
+        // Suppress silly cookie warnings.
+        Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.SEVERE);
+        Logger.getLogger("").getHandlers()[0].setLevel(Level.ALL);
+    }
+
+    public static void setVerboseLogging() {
+        Logger.getLogger("").setLevel(Level.INFO);
+        Logger.getLogger("org.deri.any23").setLevel(Level.ALL);
+        Logger.getLogger("").getHandlers()[0].setLevel(Level.ALL);
+    }
+
+}

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StreamUtils.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StreamUtils.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StreamUtils.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StreamUtils.java Tue Jan 10 16:32:28 2012
@@ -25,6 +25,8 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Contains general utility functions for handling streams.
@@ -38,6 +40,27 @@ public class StreamUtils {
     private StreamUtils(){}
 
     /**
+     * Returns all the lines read from an input stream.
+     *
+     * @param is input stream.
+     * @return list of not <code>null</code> lines.
+     * @throws IOException
+     */
+    public static String[] asLines(InputStream is) throws IOException {
+        final BufferedReader br = new BufferedReader(new InputStreamReader(is));
+        final List<String> lines = new ArrayList<String>();
+        try {
+            String line;
+            while ((line = br.readLine()) != null) {
+                lines.add(line);
+            }
+            return lines.toArray( new String[ lines.size() ] );
+        } finally {
+            closeGracefully(br);
+        }
+    }
+
+    /**
      * Returns the string content of a stream.
      *
      * @param is input stream.

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StringUtils.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StringUtils.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/util/StringUtils.java Tue Jan 10 16:32:28 2012
@@ -154,5 +154,21 @@ public class StringUtils {
         return escapeDoubleQuotes( in.replaceAll("\n", "\\\\n") );
     }
 
+    /**
+     * Builds a string composed of the given char <code>c<code/> <code>n</code> times.
+     *
+     * @param c char to be multiplied.
+     * @param times number of times.
+     * @return the string containing the multiplied char.
+     */
+    public static String multiply(char c, int times) {
+        if(times <= 0) throw new IllegalArgumentException("Invalid number of times, must be > 0 .");
+        final char[] buffer = new char[times];
+        for(int i = 0; i < times; i++) {
+            buffer[i] = c;
+        }
+        return new String(buffer);
+    }
+
     private StringUtils() {}
 }

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/DOAC.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/DOAC.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/DOAC.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/DOAC.java Tue Jan 10 16:32:28 2012
@@ -55,21 +55,21 @@ public class DOAC extends Vocabulary {
     public final URI reference_type      = createProperty(NS, "reference-type");
 
     // Resources.
-    public final URI Publication         = createResource(NS, "Publication");
-    public final URI Education           = createResource(NS, "Education");
-    public final URI OrganisationalSkill = createResource(NS, "OrganisationalSkill");
-    public final URI PrimarySchool       = createResource(NS, "PrimarySchool");
-    public final URI Reference           = createResource(NS, "Reference");
-    public final URI DrivingSkill        = createResource(NS, "DrivingSkill");
-    public final URI Degree              = createResource(NS, "Degree");
-    public final URI LanguageSkill       = createResource(NS, "LanguageSkill");
-    public final URI Skill               = createResource(NS, "Skill");
-    public final URI SecondarySchool     = createResource(NS, "SecondarySchool");
-    public final URI Course              = createResource(NS, "Course");
-    public final URI Experience          = createResource(NS, "Experience");
-    public final URI SocialSkill         = createResource(NS, "SocialSkill");
-    public final URI ComputerSkill       = createResource(NS, "ComputerSkill");
-    public final URI LanguageLevel       = createResource(NS, "LanguageLevel");
+    public final URI Publication         = createClass(NS, "Publication");
+    public final URI Education           = createClass(NS, "Education");
+    public final URI OrganisationalSkill = createClass(NS, "OrganisationalSkill");
+    public final URI PrimarySchool       = createClass(NS, "PrimarySchool");
+    public final URI Reference           = createClass(NS, "Reference");
+    public final URI DrivingSkill        = createClass(NS, "DrivingSkill");
+    public final URI Degree              = createClass(NS, "Degree");
+    public final URI LanguageSkill       = createClass(NS, "LanguageSkill");
+    public final URI Skill               = createClass(NS, "Skill");
+    public final URI SecondarySchool     = createClass(NS, "SecondarySchool");
+    public final URI Course              = createClass(NS, "Course");
+    public final URI Experience          = createClass(NS, "Experience");
+    public final URI SocialSkill         = createClass(NS, "SocialSkill");
+    public final URI ComputerSkill       = createClass(NS, "ComputerSkill");
+    public final URI LanguageLevel       = createClass(NS, "LanguageLevel");
 
     private DOAC(){
         super(NS);

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/FOAF.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/FOAF.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/FOAF.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/FOAF.java Tue Jan 10 16:32:28 2012
@@ -90,18 +90,18 @@ public class FOAF extends Vocabulary {
     public final URI jabberID                = createProperty(NS, "jabberID");
 
     // Resources.
-    public final URI Person                  = createResource(NS, "Person");
-    public final URI PersonalProfileDocument = createResource(NS, "PersonalProfileDocument");
-    public final URI Project                 = createResource(NS, "Project");
-    public final URI OnlineChatAccount       = createResource(NS, "OnlineChatAccount");
-    public final URI OnlineAccount           = createResource(NS, "OnlineAccount");
-    public final URI Agent                   = createResource(NS, "Agent");
-    public final URI Group                   = createResource(NS, "Group");
-    public final URI OnlineGamingAccount     = createResource(NS, "OnlineGamingAccount");
-    public final URI OnlineEcommerceAccount  = createResource(NS, "OnlineEcommerceAccount");
-    public final URI Document                = createResource(NS, "Document");
-    public final URI Organization            = createResource(NS, "Organization");
-    public final URI Image                   = createResource(NS, "Image");
+    public final URI Person                  = createClass(NS, "Person");
+    public final URI PersonalProfileDocument = createClass(NS, "PersonalProfileDocument");
+    public final URI Project                 = createClass(NS, "Project");
+    public final URI OnlineChatAccount       = createClass(NS, "OnlineChatAccount");
+    public final URI OnlineAccount           = createClass(NS, "OnlineAccount");
+    public final URI Agent                   = createClass(NS, "Agent");
+    public final URI Group                   = createClass(NS, "Group");
+    public final URI OnlineGamingAccount     = createClass(NS, "OnlineGamingAccount");
+    public final URI OnlineEcommerceAccount  = createClass(NS, "OnlineEcommerceAccount");
+    public final URI Document                = createClass(NS, "Document");
+    public final URI Organization            = createClass(NS, "Organization");
+    public final URI Image                   = createClass(NS, "Image");
 
     private FOAF(){
         super(NS);

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/GEO.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/GEO.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/GEO.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/GEO.java Tue Jan 10 16:32:28 2012
@@ -35,7 +35,7 @@ public class GEO extends Vocabulary {
     }
 
     // Resources.
-    public final URI Point = createResource(NS, "Point");
+    public final URI Point = createClass(NS, "Point");
 
     // Properties
     public final URI lat = createProperty(NS, "lat" );

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HLISTING.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HLISTING.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HLISTING.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HLISTING.java Tue Jan 10 16:32:28 2012
@@ -38,24 +38,24 @@ public class HLISTING extends Vocabulary
     }
 
     // Resources.
-    public final URI Listing = createResource("Listing");
-    public final URI Lister  = createResource("Lister" ); // isa FOAF.Person
-    public final URI Item    = createResource("Item"   ); // isa ?
+    public final URI Listing = createClass("Listing");
+    public final URI Lister  = createClass("Lister" ); // isa FOAF.Person
+    public final URI Item    = createClass("Item"   ); // isa ?
 
     // Properties.
     public final URI action = createProperty("action");
     public final URI lister = createProperty("lister"); // ranges over Lister
     public final URI item   = createProperty("item"  );
 
-    public final URI sell     = createResource("sell"    );
-    public final URI rent     = createResource("rent"    );
-    public final URI trade    = createResource("trade"   );
-    public final URI meet     = createResource("meet"    );
-    public final URI announce = createResource("announce");
-    public final URI offer    = createResource("offer"   );
-    public final URI wanted   = createResource("wanted"  );
-    public final URI event    = createResource("event"   );
-    public final URI service  = createResource("service" );
+    public final URI sell     = createClass("sell"    );
+    public final URI rent     = createClass("rent"    );
+    public final URI trade    = createClass("trade"   );
+    public final URI meet     = createClass("meet"    );
+    public final URI announce = createClass("announce");
+    public final URI offer    = createClass("offer"   );
+    public final URI wanted   = createClass("wanted"  );
+    public final URI event    = createClass("event"   );
+    public final URI service  = createClass("service" );
 
     public final URI tel       = VCARD.getInstance().tel;
     public final URI dtlisted  = createProperty("dtlisted" );
@@ -86,8 +86,8 @@ public class HLISTING extends Vocabulary
         return createProperty(NS, localName);
     }
 
-    private URI createResource(String localName) {
-        return createResource(NS, localName);
+    private URI createClass(String localName) {
+        return createClass(NS, localName);
     }
 
     private HLISTING(){

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HRECIPE.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HRECIPE.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HRECIPE.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/HRECIPE.java Tue Jan 10 16:32:28 2012
@@ -21,10 +21,10 @@ public class HRECIPE extends Vocabulary 
     }
 
     // Resources.
-    public URI Recipe     = createResource(NS, "Recipe");
-    public URI Duration   = createResource(NS, "Duration");
-    public URI Ingredient = createResource(NS, "Ingredient");
-    public URI Nutrition  = createResource(NS, "Nutrition");
+    public URI Recipe     = createClass(NS, "Recipe");
+    public URI Duration   = createClass(NS, "Duration");
+    public URI Ingredient = createClass(NS, "Ingredient");
+    public URI Nutrition  = createClass(NS, "Nutrition");
 
     // Properties.
     public URI fn                     = createProperty(NS, "fn");

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/ICAL.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/ICAL.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/ICAL.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/ICAL.java Tue Jan 10 16:32:28 2012
@@ -19,7 +19,7 @@ package org.deri.any23.vocab;
 import org.openrdf.model.URI;
 
 /**
- * Vocabulary definitions from ical.rdf
+ * Vocabulary definitions from <code>ical.rdf</code>
  */
 public class ICAL extends Vocabulary {
 
@@ -42,53 +42,52 @@ public class ICAL extends Vocabulary {
      */
     public final URI NAMESPACE = createURI(NS);
 
-    public final URI DomainOf_rrule = createResource("DomainOf_rrule");
-
-    public final URI List_of_Float = createResource("List_of_Float");
+    public final URI DomainOf_rrule = createClass("DomainOf_rrule");
+    public final URI List_of_Float  = createClass("List_of_Float");
 
     /**
      * Provide a grouping of component properties that define an alarm..
      */
-    public final URI Valarm = createResource("Valarm");
+    public final URI Valarm            = createClass("Valarm");
 
-    public final URI Value_CAL_ADDRESS = createResource("Value_CAL-ADDRESS");
+    public final URI Value_CAL_ADDRESS = createClass("Value_CAL-ADDRESS");
 
-    public final URI Value_DATE = createResource("Value_DATE");
+    public final URI Value_DATE        = createClass("Value_DATE");
 
-    public final URI Value_DURATION = createResource("Value_DURATION");
+    public final URI Value_DURATION    = createClass("Value_DURATION");
 
-    public final URI Value_PERIOD = createResource("Value_PERIOD");
+    public final URI Value_PERIOD      = createClass("Value_PERIOD");
 
-    public final URI Value_RECUR = createResource("Value_RECUR");
+    public final URI Value_RECUR       = createClass("Value_RECUR");
 
-    public final URI Vcalendar = createResource("vcalendar");
+    public final URI Vcalendar         = createClass("vcalendar");
 
     /**
      * Provide a grouping of component properties that describe an event..
      */
-    public final URI Vevent = createResource("Vevent");
+    public final URI Vevent = createClass("Vevent");
 
     /**
      * Provide a grouping of component properties that describe either a request
      * for free/busy time, describe a response to a request for free/busy time or
      * describe a published set of busy time..
      */
-    public final URI Vfreebusy = createResource("Vfreebusy");
+    public final URI Vfreebusy = createClass("Vfreebusy");
 
     /**
      * Provide a grouping of component properties that describe a journal entry..
      */
-    public final URI Vjournal = createResource("Vjournal");
+    public final URI Vjournal = createClass("Vjournal");
 
     /**
      * Provide a grouping of component properties that defines a time zone..
      */
-    public final URI Vtimezone = createResource("Vtimezone");
+    public final URI Vtimezone = createClass("Vtimezone");
 
     /**
      * Provide a grouping of calendar properties that describe a to-do..
      */
-    public final URI Vtodo = createResource("Vtodo");
+    public final URI Vtodo = createClass("Vtodo");
 
 
     /**
@@ -101,13 +100,10 @@ public class ICAL extends Vocabulary {
      * The URI defines an "Attendee" within a calendar component.value type:
      * CAL-ADDRESS.
      */
-    public final URI attendee = createProperty("attendee");
-
+    public final URI attendee   = createProperty("attendee");
     public final URI calAddress = createProperty("calAddress");
-
-    public final URI component = createProperty("component");
-
-    public final URI daylight = createProperty("daylight");
+    public final URI component  = createProperty("component");
+    public final URI daylight  = createProperty("daylight");
 
     /**
      * The URI specifies a positive duration of time.value type: DURATION.
@@ -515,8 +511,8 @@ public class ICAL extends Vocabulary {
      */
     public final URI version = createProperty("version");
 
-    private URI createResource(String string) {
-        return createResource(NS, string);
+    private URI createClass(String string) {
+        return createClass(NS, string);
     }
 
     private URI createProperty(String string) {

Added: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/OGP.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/OGP.java?rev=1229627&view=auto
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/OGP.java (added)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/OGP.java Tue Jan 10 16:32:28 2012
@@ -0,0 +1,149 @@
+/**
+ * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
+ *
+ * Licensed 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.deri.any23.vocab;
+
+import org.openrdf.model.URI;
+
+/**
+ * The <a href="http://ogp.me/">Open Graph Protocol</> vocabulary.
+ *
+ * @author Michele Mostarda (mostarda@fbk.eu)
+ */
+public class OGP extends Vocabulary {
+
+    public static final String NS = "http://ogp.me/ns#";
+    
+    /* BEGIN: Basic Metadata. */
+
+    /** The title of your object as it should appear within the graph (Facebook Graph API). */
+    public static final String TITLE = "title";
+    /** The type of your object, e.g., <code>video.movie</code>.
+     *  Depending on the type you specify, other properties may also be required. */
+    public static final String TYPE  = "type";
+    /** An image URL which should represent your object within the graph. */
+    public static final String URL   = "url";
+    /** The canonical URL of your object that will be used as its permanent ID in the graph (Facebook Graph API). */
+    public static final String IMAGE = "image";
+
+    /* END: Basic Metadata. */
+
+    /* BEGIN: Optional Metadata. */
+
+    /** A URL to an audio file to accompany this object. */
+    public static final String AUDIO = "audio";
+    /** A one to two sentence description of your object. */
+    public static final String DESCRIPTION = "description";
+    /** The word that appears before this object's title in a sentence. An enum of (a, an, the, "", auto).
+     *  If auto is chosen, the consumer of your data should chose between "a" or "an". Default is "" (blank). */
+    public static final String DETERMINER = "determiner";
+    /** The locale these tags are marked up in. Of the format <code>language_TERRITORY</code>.
+     *  Default is <code>en_US</code>. */
+    public static final String LOCALE = "locale";
+    /** An array of other locales this page is available in. */
+    public static final String LOCALE__ALTERNATE = "locale:alternate";
+    /** If your object is part of a larger web site, the name which should be
+     *  displayed for the overall site. e.g., <b>IMDb</b>. */
+    public static final String SITE_NAME = "site_name";
+    /** A URL to a video file that complements this object. */
+    public static final String VIDEO = "video";
+
+    /* END: Optional Metadata. */
+
+    /* BEGIN: Structured Properties. */
+
+    /** Identical to <code>og:image</code>. */
+    public static final String IMAGE__URL        = "image:url";
+    /** An alternate url to use if the webpage requires <b>HTTPS</b>. */
+    public static final String IMAGE__SECURE_URL = "image:secure_url";
+    /** A <i>MIME type</i> for this image. */
+    public static final String IMAGE__TYPE       = "image:type";
+    /** The number of pixels wide. */
+    public static final String IMAGE__WIDTH      = "image:width";
+    /** The number of pixels high. */
+    public static final String IMAGE__HEIGHT     = "image:height";
+
+    /** Video URL. */
+    public static final String VIDEO__URL        = "video:url";
+    /** An alternate url to use if the webpage requires <b>HTTPS</b>. */
+    public static final String VIDEO__SECURE_URL = "video:secure_url";
+    /** A <i>MIME type</i> for this video. */
+    public static final String VIDEO__TYPE       = "video:type";
+    /** The number of pixels wide. */
+    public static final String VIDEO__WIDTH      = "video:width";
+    /** The number of pixels height. */
+    public static final String VIDEO__HEIGHT     = "video:height";
+
+    /** An alternate url to use if the webpage requires <b>HTTPS</b>. */
+    public static final String AUDIO__SECURE_URL = "audio:secure_url";
+    /** A <i>MIME type</i> for this audio. */
+    public static final String AUDIO__TYPE       = "audio:type";
+
+    /* END: Structured Properties. */
+
+    private static OGP instance;
+
+    public static OGP getInstance() {
+        if(instance == null) {
+            instance = new OGP();
+        }
+        return instance;
+    }
+
+    public final URI NAMESPACE = createURI(NS);
+    
+
+    public final URI title           = createProperty(TITLE);
+    public final URI type            = createProperty(TYPE);
+    public final URI url             = createProperty(URL);
+    public final URI image           = createProperty(IMAGE);
+    public final URI description     = createProperty(DESCRIPTION);
+    public final URI determiner      = createProperty(DETERMINER);
+    public final URI locale          = createProperty(LOCALE);
+    public final URI localeAlternate = createProperty(LOCALE__ALTERNATE);
+    public final URI siteName        = createProperty(SITE_NAME);
+    public final URI video           = createProperty(VIDEO);
+
+    public final URI imageURL       = createProperty(IMAGE__URL);
+    public final URI imageSecureURL = createProperty(IMAGE__SECURE_URL);
+    public final URI imageType      = createProperty(IMAGE__TYPE);
+    public final URI imageWidth     = createProperty(IMAGE__WIDTH);
+    public final URI imageHeight    = createProperty(IMAGE__HEIGHT);
+
+    public final URI videoURL       = createProperty(VIDEO__URL);
+    public final URI videoSecureURL = createProperty(VIDEO__SECURE_URL);
+    public final URI videoType      = createProperty(VIDEO__TYPE);
+    public final URI videoWidth     = createProperty(VIDEO__WIDTH);
+    public final URI videoHeight    = createProperty(VIDEO__HEIGHT);
+
+    public final URI audio          = createProperty(AUDIO);
+    public final URI audioSecureURL = createProperty(AUDIO__SECURE_URL);
+    public final URI audioType      = createProperty(AUDIO__TYPE);
+
+    private URI createClass(String localName) {
+        return createClass(NS, localName);
+    }
+
+    private URI createProperty(String localName) {
+        return createProperty(NS, localName);
+    }
+
+    private OGP() {
+        super(NS);
+    }
+
+}

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/RDFSchemaUtils.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/RDFSchemaUtils.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/RDFSchemaUtils.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/RDFSchemaUtils.java Tue Jan 10 16:32:28 2012
@@ -16,9 +16,10 @@
 
 package org.deri.any23.vocab;
 
-import org.deri.any23.parser.NQuadsWriter;
+import org.deri.any23.io.nquads.NQuadsWriter;
 import org.deri.any23.rdf.RDFUtils;
 import org.deri.any23.util.DiscoveryUtils;
+import org.deri.any23.util.StringUtils;
 import org.openrdf.model.URI;
 import org.openrdf.model.vocabulary.RDF;
 import org.openrdf.model.vocabulary.RDFS;
@@ -28,9 +29,10 @@ import org.openrdf.rio.ntriples.NTriples
 import org.openrdf.rio.rdfxml.RDFXMLWriter;
 
 import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
+import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.util.List;
+import java.util.Map;
 
 /**
  * This class provides a set of methods for generating
@@ -40,6 +42,8 @@ import java.util.List;
  */
 public class RDFSchemaUtils {
 
+    private static final String RDF_XML_SEPARATOR = StringUtils.multiply('=', 100);
+    
     /**
      * Supported formats for vocabulary serialization.
      */
@@ -54,25 +58,33 @@ public class RDFSchemaUtils {
      * <code>resources</code> and <code>properties</code>.
      *
      * @param namespace vocabulary namespace.
-     * @param resources list of resources.
+     * @param classes list of classes.
      * @param properties list of properties.
+     * @param comments map of resource comments.
      * @param writer writer to print out the RDF Schema triples.
      * @throws RDFHandlerException
      */
     public static void serializeVocabulary(
             URI namespace,
-            URI[] resources,
+            URI[] classes,
             URI[] properties,
+            Map<URI,String> comments,
             RDFWriter writer
     ) throws RDFHandlerException {
         writer.startRDF();
-        for(URI entity : resources) {
-            writer.handleStatement( RDFUtils.quad(entity, RDF.TYPE, RDFS.CLASS  , namespace)  );
-            writer.handleStatement( RDFUtils.quad(entity, RDFS.MEMBER, namespace, namespace)  );
+        for(URI clazz : classes) {
+            writer.handleStatement( RDFUtils.quad(clazz, RDF.TYPE, RDFS.CLASS  , namespace) );
+            writer.handleStatement( RDFUtils.quad(clazz, RDFS.MEMBER, namespace, namespace) );
+            final String comment = comments.get(clazz);
+            if(comment != null)
+                writer.handleStatement( RDFUtils.quad(clazz, RDFS.COMMENT, RDFUtils.literal(comment), namespace) );
         }
         for(URI property : properties) {
             writer.handleStatement(RDFUtils.quad(property, RDF.TYPE, RDF.PROPERTY, namespace));
             writer.handleStatement(RDFUtils.quad(property, RDFS.MEMBER, namespace, namespace));
+            final String comment = comments.get(property);
+            if(comment != null)
+                writer.handleStatement( RDFUtils.quad(property, RDFS.COMMENT, RDFUtils.literal(comment), namespace) );
         }
         writer.endRDF();
     }
@@ -88,8 +100,9 @@ public class RDFSchemaUtils {
     throws RDFHandlerException {
         serializeVocabulary(
                 vocabulary.getNamespace(),
-                vocabulary.getResources(),
+                vocabulary.getClasses(),
                 vocabulary.getProperties(),
+                vocabulary.getComments(),
                 writer
         );
     }
@@ -99,18 +112,27 @@ public class RDFSchemaUtils {
      *
      * @param vocabulary vocabulary to be serialized.
      * @param format output format for vocabulary.
-     * @param os output stream.
+     * @param willFollowAnother if <code>true</code> another vocab will be printed in the same stream.
+     * @param ps output stream.
      * @throws RDFHandlerException
      */
-    public static void serializeVocabulary(Vocabulary vocabulary, VocabularyFormat format, OutputStream os)
-    throws RDFHandlerException {
+    public static void serializeVocabulary(
+            Vocabulary vocabulary,
+            VocabularyFormat format,
+            boolean willFollowAnother,
+            PrintStream ps
+    ) throws RDFHandlerException {
         final RDFWriter rdfWriter;
         if(format == VocabularyFormat.RDFXML) {
-            rdfWriter = new RDFXMLWriter(os);
+            rdfWriter = new RDFXMLWriter(ps);
+            if(willFollowAnother)
+                ps.print("\n");
+                ps.print(RDF_XML_SEPARATOR);
+                ps.print("\n");
         } else if(format == VocabularyFormat.NTriples) {
-            rdfWriter = new NTriplesWriter(os);
+            rdfWriter = new NTriplesWriter(ps);
         } else if(format == VocabularyFormat.NQuads) {
-            rdfWriter = new NQuadsWriter(os);
+            rdfWriter = new NQuadsWriter(ps);
         }
         else {
             throw new IllegalArgumentException("Unsupported format " + format);
@@ -129,7 +151,9 @@ public class RDFSchemaUtils {
     public static String serializeVocabulary(Vocabulary vocabulary, VocabularyFormat format)
     throws RDFHandlerException {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        serializeVocabulary(vocabulary, format, baos);
+        final PrintStream ps = new PrintStream(baos);
+        serializeVocabulary(vocabulary, format, false, ps);
+        ps.close();
         return baos.toString();
     }
 
@@ -137,14 +161,15 @@ public class RDFSchemaUtils {
      * Serializes all the vocabularies to <i>NQuads</i> over the given output stream.
      *
      * @param format output format for vocabularies.
-     * @param os output stream.
+     * @param ps output print stream.
      */
-    public static void serializeVocabularies(VocabularyFormat format, OutputStream os) {
+    public static void serializeVocabularies(VocabularyFormat format, PrintStream ps) {
         final Class vocabularyClass = Vocabulary.class;
         final List<Class> vocabularies = DiscoveryUtils.getClassesInPackage(
                 vocabularyClass.getPackage().getName(),
                 vocabularyClass
         );
+        int currentIndex = 0;
         for (Class vocabClazz : vocabularies) {
             final Vocabulary instance;
             try {
@@ -155,7 +180,7 @@ public class RDFSchemaUtils {
                 throw new RuntimeException("Error while instantiating vocabulary class " + vocabClazz, e);
             }
             try {
-                serializeVocabulary(instance, format, os);
+                serializeVocabulary(instance, format, currentIndex < vocabularies.size() - 2, ps);
             } catch (RDFHandlerException rdfhe) {
                 throw new RuntimeException("Error while serializing vocabulary.", rdfhe);
             }

Modified: incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/SINDICE.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/SINDICE.java?rev=1229627&r1=1229626&r2=1229627&view=diff
==============================================================================
--- incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/SINDICE.java (original)
+++ incubator/any23/trunk/any23-core/src/main/java/org/deri/any23/vocab/SINDICE.java Tue Jan 10 16:32:28 2012
@@ -43,7 +43,7 @@ public class SINDICE extends Vocabulary 
     /**
      * The namespace of the vocabulary as a string.
      */
-    public static final String NS = "http://vocab.sindice.net/";
+    public static final String NS = "http://vocab.sindice.net/any23#";
 
     private static SINDICE instance;
 
@@ -57,7 +57,7 @@ public class SINDICE extends Vocabulary 
     /**
      * The namespace of the vocabulary as a URI.
      */
-    public final URI NAMESPACE = createResource(NS);
+    public final URI NAMESPACE = createURI(NS);
 
     /**
      * This property expresses the DNS domain of the resource on which
@@ -94,8 +94,8 @@ public class SINDICE extends Vocabulary 
     public final URI date = createProperty(DATE);
 
 
-    private URI createResource(String localName) {
-        return createResource(NS, localName);
+    private URI createClass(String localName) {
+        return createClass(NS, localName);
     }
 
     private URI createProperty(String localName) {



Mime
View raw message