Return-Path: Delivered-To: apmail-incubator-clerezza-commits-archive@minotaur.apache.org Received: (qmail 28296 invoked from network); 14 Jan 2011 02:38:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jan 2011 02:38:13 -0000 Received: (qmail 81895 invoked by uid 500); 14 Jan 2011 02:38:13 -0000 Delivered-To: apmail-incubator-clerezza-commits-archive@incubator.apache.org Received: (qmail 81873 invoked by uid 500); 14 Jan 2011 02:38:13 -0000 Mailing-List: contact clerezza-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: clerezza-dev@incubator.apache.org Delivered-To: mailing list clerezza-commits@incubator.apache.org Received: (qmail 81866 invoked by uid 99); 14 Jan 2011 02:38:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jan 2011 02:38:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jan 2011 02:38:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 50E0223888FE; Fri, 14 Jan 2011 02:37:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1058842 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/clerezza/ src/main/java/org/apa... Date: Fri, 14 Jan 2011 02:37:44 -0000 To: clerezza-commits@incubator.apache.org From: hasan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110114023744.50E0223888FE@eris.apache.org> Author: hasan Date: Fri Jan 14 02:37:43 2011 New Revision: 1058842 URL: http://svn.apache.org/viewvc?rev=1058842&view=rev Log: CLEREZZA-392: initial version Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/ (with props) incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/pom.xml incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/ (with props) incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/ParserFactory.java incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProvider.java incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameRdfHandler.java incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameScbConverter.java incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/parser/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProviderTest.java incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.nt incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.rdf incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.ttl Propchange: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Jan 14 02:37:43 2011 @@ -0,0 +1,4 @@ +.classpath +.settings +target +.project Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/pom.xml URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/pom.xml?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/pom.xml (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/pom.xml Fri Jan 14 02:37:43 2011 @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.apache.clerezza + org.apache.clerezza.parent + 0.2-incubating-SNAPSHOT + + org.apache.clerezza + org.apache.clerezza.rdf.sesame.parser + 0.1-incubating-SNAPSHOT + bundle + Clerezza - SCB Sesame-based Parser + An RDF parser based on Sesame + + + junit + junit + test + + + org.osgi + org.osgi.core + + + org.osgi + org.osgi.compendium + + + org.apache.clerezza + org.apache.clerezza.rdf.core + + + org.apache.clerezza.ext + org.openrdf.sesame + + + Propchange: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Jan 14 02:37:43 2011 @@ -0,0 +1 @@ +pom.xml Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/ParserFactory.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/ParserFactory.java?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/ParserFactory.java (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/ParserFactory.java Fri Jan 14 02:37:43 2011 @@ -0,0 +1,59 @@ +/* + * 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.clerezza.rdf.sesame.parser; + +import java.util.HashMap; +import java.util.Map; +import org.apache.clerezza.rdf.core.serializedform.SupportedFormat; +import org.openrdf.rio.RDFParser; +import org.openrdf.rio.RDFParserFactory; +import org.openrdf.rio.n3.N3ParserFactory; +import org.openrdf.rio.ntriples.NTriplesParserFactory; +import org.openrdf.rio.rdfxml.RDFXMLParserFactory; +import org.openrdf.rio.turtle.TurtleParserFactory; + +/** + * + * @author hasan + */ +public class ParserFactory { + private static final Map factories = new HashMap(); + static { + factories.put(SupportedFormat.RDF_XML, new RDFXMLParserFactory()); + factories.put(SupportedFormat.N_TRIPLE, new NTriplesParserFactory()); + factories.put(SupportedFormat.X_TURTLE, new TurtleParserFactory()); + factories.put(SupportedFormat.TURTLE, new TurtleParserFactory()); + factories.put(SupportedFormat.N3, new N3ParserFactory()); + // other parser factories can be added in future if needed: + // TriXParserFactory, TriGParserFactory, and RDFaHtmlParserFactory + } + + private ParserFactory() { + } + + public static RDFParser createRdfParser(String format) { + RDFParserFactory factory = factories.get(format); + if (factory == null) { + return null; + } + return factory.getParser(); + } +} Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProvider.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProvider.java?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProvider.java (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProvider.java Fri Jan 14 02:37:43 2011 @@ -0,0 +1,73 @@ +/* + * 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.clerezza.rdf.sesame.parser; + +import java.io.IOException; +import java.io.InputStream; +import org.apache.clerezza.rdf.core.MGraph; +import org.apache.clerezza.rdf.core.serializedform.ParsingProvider; +import org.apache.clerezza.rdf.core.serializedform.SupportedFormat; +import org.apache.clerezza.rdf.core.UriRef; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Service; +import org.apache.clerezza.rdf.core.serializedform.UnsupportedParsingFormatException; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParseException; +import org.openrdf.rio.RDFParser; + +/** + * A {@link org.apache.clerezza.rdf.core.serializedform.ParsingProvider} based on Sesame + * + * @author hasan + */ + +@Component(immediate=true) +@Service(ParsingProvider.class) +@Property(name="supportedFormat", value={SupportedFormat.RDF_XML, + SupportedFormat.TURTLE, SupportedFormat.X_TURTLE, + SupportedFormat.N_TRIPLE, SupportedFormat.N3}) +@SupportedFormat({SupportedFormat.RDF_XML, + SupportedFormat.TURTLE, SupportedFormat.X_TURTLE, + SupportedFormat.N_TRIPLE, SupportedFormat.N3}) +public class SesameParserProvider implements ParsingProvider { + + @Override + public void parse(MGraph target, InputStream serializedGraph, String formatIdentifier, UriRef baseUri) { + + RDFParser rdfParser = ParserFactory.createRdfParser(formatIdentifier); + if (rdfParser == null) { + throw new UnsupportedParsingFormatException(formatIdentifier); + } + SesameRdfHandler sesameRdfHandler = new SesameRdfHandler(target); + rdfParser.setRDFHandler(sesameRdfHandler); + String base = (baseUri == null) ? "http://relative-uri.fake/" : baseUri.getUnicodeString(); + try { + rdfParser.parse(serializedGraph, base); + } catch (IOException ex) { + throw new RuntimeException(ex); + } catch (RDFParseException ex) { + throw new RuntimeException(ex); + } catch (RDFHandlerException ex) { + throw new RuntimeException(ex); + } + } +} Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameRdfHandler.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameRdfHandler.java?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameRdfHandler.java (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameRdfHandler.java Fri Jan 14 02:37:43 2011 @@ -0,0 +1,63 @@ +/* + * 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.clerezza.rdf.sesame.parser; + +import org.apache.clerezza.rdf.core.TripleCollection; +import org.openrdf.model.Statement; +import org.openrdf.rio.RDFHandler; +import org.openrdf.rio.RDFHandlerException; + +/** + * + * @author hasan + */ +public class SesameRdfHandler implements RDFHandler { + + final TripleCollection tc; + private SesameScbConverter sesameScbConverter; + + public SesameRdfHandler(TripleCollection tc) { + this.tc = tc; + } + + @Override + public void startRDF() throws RDFHandlerException { + sesameScbConverter = new SesameScbConverter(); + } + + @Override + public void endRDF() throws RDFHandlerException { + sesameScbConverter = null; + } + + @Override + public void handleNamespace(String string, String string1) throws RDFHandlerException { + } + + @Override + public void handleStatement(Statement stmnt) throws RDFHandlerException { + tc.add(sesameScbConverter.createTriple(stmnt)); + } + + @Override + public void handleComment(String string) throws RDFHandlerException { + } +} Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameScbConverter.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameScbConverter.java?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameScbConverter.java (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/main/java/org/apache/clerezza/rdf/sesame/parser/SesameScbConverter.java Fri Jan 14 02:37:43 2011 @@ -0,0 +1,124 @@ +/* + * 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.clerezza.rdf.sesame.parser; + +import java.util.HashMap; +import java.util.Map; +import org.apache.clerezza.rdf.core.BNode; +import org.apache.clerezza.rdf.core.Language; +import org.apache.clerezza.rdf.core.Literal; +import org.apache.clerezza.rdf.core.NonLiteral; +import org.apache.clerezza.rdf.core.Resource; +import org.apache.clerezza.rdf.core.Triple; +import org.apache.clerezza.rdf.core.UriRef; +import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl; +import org.apache.clerezza.rdf.core.impl.TripleImpl; +import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl; +import org.openrdf.model.Statement; + +/** + * + * @author hasan + */ +public class SesameScbConverter { + + private final Map bNodesMap = new HashMap(); + + /** + * Create a {@link org.apache.clerezza.rdf.core.Triple} instance from a {@link org.openrdf.model.Statement} + * + * @param statement + * @return a new TripleImpl instance + */ + public Triple createTriple(Statement statement) { + NonLiteral subject = createNonLiteral(statement.getSubject()); + UriRef predicate = createUriRef(statement.getPredicate()); + Resource resource = createResource(statement.getObject()); + return new TripleImpl(subject, predicate, resource); + } + + /** + * Create a {@link org.apache.clerezza.rdf.core.NonLiteral} instance from a {@link org.openrdf.model.Resource} + * + * @param resource + * @return a new UriRef or a BNode instance. The BNode instance is new if it does not exist before + */ + public NonLiteral createNonLiteral(org.openrdf.model.Resource resource) { + if (resource instanceof org.openrdf.model.BNode) { + org.openrdf.model.BNode sesameBNode = (org.openrdf.model.BNode) resource; + return getOrCreateBNode(sesameBNode); + } else { + org.openrdf.model.URI uri = (org.openrdf.model.URI) resource; + return createUriRef(uri); + } + } + + private org.apache.clerezza.rdf.core.BNode getOrCreateBNode(org.openrdf.model.BNode sesameBNode) { + BNode result = bNodesMap.get(sesameBNode); + + if (result == null) { + result = new BNode(); + bNodesMap.put(sesameBNode, result); + } + return result; + } + + /** + * Create a {@link org.apache.clerezza.rdf.core.UriRef} instance from a {@link org.openrdf.model.URI} + * + * @param uri + * @return a new UriRef instance + */ + public UriRef createUriRef(org.openrdf.model.URI uri) { + return new UriRef(uri.stringValue()); + } + + /** + * Create a {@link org.apache.clerezza.rdf.core.Resource} instance from a {@link org.openrdf.model.Value} + * + * @param value + * @return a new PlainLiteralImpl, a new TypedLiteralImpl, a new UriRef, or a BNode instance + */ + public Resource createResource(org.openrdf.model.Value value) { + if (value instanceof org.openrdf.model.Literal) { + return createLiteral((org.openrdf.model.Literal) value); + } else { + return createNonLiteral((org.openrdf.model.Resource) value); + } + } + + /** + * Create a {@link org.apache.clerezza.rdf.core.Literal} instance from a {@link org.openrdf.model.Literal} + * + * @param literal + * @return a new PlainLiteralImpl or TypedLiteralImpl instance + */ + public Literal createLiteral(org.openrdf.model.Literal literal) { + org.openrdf.model.URI dataType = literal.getDatatype(); + if (dataType == null) { + String languageString = literal.getLanguage(); + Language language = languageString == null ? null : new Language(languageString); + return new PlainLiteralImpl(literal.getLabel(), language); + } else { + return new TypedLiteralImpl(literal.getLabel(), createUriRef(dataType)); + } + } +} Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProviderTest.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProviderTest.java?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProviderTest.java (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/java/org/apache/clerezza/rdf/sesame/parser/SesameParserProviderTest.java Fri Jan 14 02:37:43 2011 @@ -0,0 +1,72 @@ +/* + * 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.clerezza.rdf.sesame.parser; + +import java.io.InputStream; + +import org.junit.Assert; +import org.junit.Test; +import org.apache.clerezza.rdf.core.Graph; +import org.apache.clerezza.rdf.core.MGraph; +import org.apache.clerezza.rdf.core.UriRef; +import org.apache.clerezza.rdf.core.impl.SimpleMGraph; +import org.apache.clerezza.rdf.core.serializedform.ParsingProvider; +import org.apache.clerezza.rdf.core.serializedform.SupportedFormat; + +/** + * Tests taken from http://www.w3.org/2001/sw/DataAccess/df1/tests/ + * + * @author hasan + */ +public class SesameParserProviderTest { + + /* + * comparing result from nt and turtle parsing, + */ + @Test + public void testTurtleParser() { + ParsingProvider provider = new SesameParserProvider(); + InputStream nTriplesIn = getClass().getResourceAsStream("test-04.nt"); + InputStream turtleIn = getClass().getResourceAsStream("test-04.ttl"); + Graph graphFromNTriples = parse(provider, nTriplesIn, SupportedFormat.N_TRIPLE, null); + Graph graphFromTurtle = parse(provider, turtleIn, SupportedFormat.TURTLE, null); + Assert.assertEquals(graphFromNTriples, graphFromTurtle); + } + + /* + * comparing result from nt and rdf/xml parsing, + */ + @Test + public void testRdfXmlParser() { + ParsingProvider provider = new SesameParserProvider(); + InputStream nTriplesIn = getClass().getResourceAsStream("test-04.nt"); + InputStream rdfXmlIn = getClass().getResourceAsStream("test-04.rdf"); + Graph graphFromNTriples = parse(provider, nTriplesIn, SupportedFormat.N_TRIPLE, null); + Graph graphFromRdfXml = parse(provider, rdfXmlIn, SupportedFormat.RDF_XML, null); + Assert.assertEquals(graphFromNTriples, graphFromRdfXml); + } + + private Graph parse(ParsingProvider parsingProvider, InputStream in, String type, UriRef base) { + MGraph simpleMGraph = new SimpleMGraph(); + parsingProvider.parse(simpleMGraph, in, type, base); + return simpleMGraph.getGraph(); + } +} Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.nt URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.nt?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.nt (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.nt Fri Jan 14 02:37:43 2011 @@ -0,0 +1,2 @@ +_:genid1 . + _:genid2 . Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.rdf URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.rdf?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.rdf (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.rdf Fri Jan 14 02:37:43 2011 @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.ttl URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.ttl?rev=1058842&view=auto ============================================================================== --- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.ttl (added) +++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.sesame.parser/src/test/resources/org/apache/clerezza/rdf/sesame/parser/test-04.ttl Fri Jan 14 02:37:43 2011 @@ -0,0 +1,4 @@ +# Test empty [] operator; not allowed as predicate +@prefix : . +[] :a :b . +:c :d [] .