Return-Path: X-Original-To: apmail-clerezza-commits-archive@www.apache.org Delivered-To: apmail-clerezza-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8FBB217C65 for ; Thu, 23 Apr 2015 20:41:05 +0000 (UTC) Received: (qmail 20637 invoked by uid 500); 23 Apr 2015 20:41:05 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 20601 invoked by uid 500); 23 Apr 2015 20:41:05 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 20478 invoked by uid 99); 23 Apr 2015 20:41:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 20:41:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3DDE3E17F8; Thu, 23 Apr 2015 20:41:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: reto@apache.org To: commits@clerezza.apache.org Date: Thu, 23 Apr 2015 20:41:12 -0000 Message-Id: <75ffae362c254d359d90233186ed371d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [08/14] clerezza git commit: CLEREZZA-966: moved stable serializer to rdf folder http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/libby.foaf ---------------------------------------------------------------------- diff --git a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/libby.foaf b/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/libby.foaf deleted file mode 100644 index c35551e..0000000 --- a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/libby.foaf +++ /dev/null @@ -1,581 +0,0 @@ - - - - - - - - - - - - - - - -Libby Miller -libby -01e253737c46286ff7cc1183be05ab64fea15438 -f68e81ac6289ffd7391bd2c53ab1dc6447d09a2e -80f78952ba7c71bc9a0a38de415692922a3f6024 -289d4d44325d0b0218edc856c8c3904fa3fd2875 -f68e81ac6289ffd7391bd2c53ab1dc6447d09a2e -01e253737c46286ff7cc1183be05ab64fea15438 - - - - - - - - - - - - - - - - - - - - - - - - - - RDFWeb codepiction - A demonstrator of codepiction of people in photos in RDFWeb - - - - - - - - - General use - A general purpose low security login for -photos, files etc. - libby - liJPZp286OEMEl - (this should be encrypted to the users public -key? - - - - - - -f30065df6b58584bd16373eee43c9f8e2ffb9a76 -89a38611df70f827f2c7c13c334bd48cbe0dc97b -Damian Steer -shellac - - - - - -362ce75324396f0aa2d3e5f1246f40bf3bb44401 -748934f32135cfcf6f8c06e253c53442721e15e7 -Dan Brickley -danbri -bandri - - - - - -eda070d04d7495fa13e43cf964526d62b60a0566 -Max Froumentin -maxf - - - - - -0a5eaa538253e5f5fdecf0c81065052f18f0ab25 -Craig Dibble - - - - - -46554fe08bec8edd3e94281377d641666ce7ecb5 -Martin Poulter - - - - - -1839a1cc2e719a85ea7d9007f587b2899cd94064 -Amy van der Hiel - - - - - -35022e505e6a64c05837eccf4beb5d8f981a4e5a -1cf334c4f66a790b9b388768d4f07e1efea40773 -Jim Ley -jibberjim - - - - - - -Chris Croome -3622df31544ccc1c46c014195083f36f9a99a348 - - - - - -Nadia Heninger -584328833bca45b9342e976291f1b55ca8d405cd - - - - - -Earle Martin -f31433ec4215e283bb07d19aa17779ad5245c796 - - - - - -Nick Gibbins -28339a9a36ee4e330da9613958efb89e2961c6cb -nmg - - - - - -Leigh Dodds -1bca73e5c6916c738d6ec7cc0597ad0e395e7ace -ldodds - - - - - -Jonathan Chetwynd -fa39428e74171a48bf7a52c737b59b290ac3c9fe - - - - - -Daniel Krech -3665f4f2370ddd6358da4062f3293f6dc7f39b7c -eikeon - - - - - -Pär Lannerö -2482e2c8a03f35a41782e0f8d620f715b944003a - - - - - - -878573be8bbd41dba97f9f376d29c29533fcb299 -Matt Biddulph -mattb - - - - - -f0e7ea3139fbe45e76b904bdb755fb0b9fce2572 -Matthew Miller - - - - - - - -542ebbcab0da94d1a5f5d6f1cb6ac9e8a9d9158e -Sarah Miller - - - - - -4829af19130151de1c4def299d73d33f33dee0fb -Jo Walsh -zool - - - - - -c66b1cf8ee172f06b7b41f9e6257623ba14eab5f -Sean B. Palmer -sbp - - - - - - - -9f33f246b39a77c1fdff99df1938ef5dac8b20e9 -Liz Dibble - - - - - - 632054bd9d1d119f99d6858ef64d3f13a3caab87 -Liz Turner -ephidrina - - - - - -7e572a9e12f2e2fac40039b3986a59daf47c9de6 -Big James - - - - - -fd991c34194a4428e70cdcc8068deaa6f35464fe -Edd Dumbill -edd - - - - - -8e26096857d5a99f23bff38a520892e336b56f7d -William Loughborough - - - - - -26cbe7a75effa2ccc5c144a43fc57e19b292393e -Wendy Chisholm - - - - - -a74399757727c5f4a48e63921b8cc206f73d5fe -Charles McCathieNevile -chaals - - - - - -970987f991961f2553a1bf2574166fa29befbccb -Dave Beckett -dajobe - - - - - -702f38a6bae2aa171191a71e2769f4daf3ef8833 -Liddy Nevile - - - - - -867ac51a36819bbc36620c41edecdc1372fb75dc -Jan Grant -jang - - - - - -8ff4ac9258e86bf5b5df2e8db23672e023c5d9dc -Paul Shabajee -pshab - - - - - -8f2f0c59ae2203bd238093e01c3954d10f90b1fb -Kate Sharp -kates - - - - - -e2d67791b2a0ce3441c0c770f94daa130b4e6d95 -5697bf372610b25e0058f5f62cc75276d9606d44 -Eric Prud'hommeaux -ericp - - - - - -69b6e650e8223013c086b0c7b275037a6c6be8eb -Margaret Hart - - - - - -94b6eb0c835f928c5ed565dc3ed1a355ac1b41e5 -Dan Connolly -danc - - - - - -7ebde4f3ecdd8ff3899cf268d20c0227bd23602f -David Miller - - - - - -fd1c7fa497930b8b24e3998927fcebe63509ef20 -Eric Miller - - - - - -1a29b5b983c8e5fc1f953eccfd384496c3ddc161 -Judith Miller - - - - - - -Lars Marius Garshol -a598db95e98e4c9e88d0b5f6741106df16ef139b -larsbot - - - - - - - 917a511baeebf5adb3265fd5323fa7bc516f2852 -Kal Ahmed - - - - - - -fdbafa77a1c811b1f9dd1b73c701ee281bfbdf69 -Mary Nishikawa - - - - - - - -feb7e9a206907a123e3f66d276b79549f1a7f3de -Aaron Swartz -aaronsw - - - - - - -f87f3b42808adf5e7f60c5df0eb98e1091d7d222 -Nicole Sullivan -nicole - - - - - - -Alberto Reggiori -e2a4008e49a394a2d46150b7d6488cd52be327e1 -1fe426b4986ce38f3be5aa84f4db5193302000c6 - -alberto - - - - - - -b2cee56f16bc7ce9c1a3f594588056119f25e2e2 -21477c8c0299c976e64b729c8f09fc3f8be307f2 -Dirk-Willem van Gulik - -dirkx - - - - - -56dbb0962ec28e8d3f77868a0ef9ba70f09f9a92 -Zavisa Bjelogrlic - -binzac - - - - - - -31c52c8f19a0c1c79addf0e87d80418ece756865 -David Norheim - - - - - - - -669fe353dbef63d12ba11f69ace8acbec1ac8b17 -Danny Ayers -danja - - - - - -6bdc3a6be4cc72c578d4ab01a618bbd9563bcd5b -Graham Klyne -gk - - - - - -ffff2cddff6ce89ad0d25ffccc4f0051caf8d6e0 -Masahide Kanzaki -masaka - - - - - -44bc4fed584a2d1ac8fc55206db67656165d67fd -Steve Harris -swh - - - - - -65b983bb397fb71849da910996741752ace8369b -Morten Frederiksen -mortenf - - - - - -dae368b5acd44c3cbe9ba8d25c1e54df3391ea8c -Jipp -jipp - - - - - -f80a0f19d2a0897b89f48647b2fb5ca1f0bc1cb8 -Greg Williams -kasei - - - - - -927ed281057a507d882338eb57f74551f6771325 -Ludovic Hirlimann -lhirlimann - - - - - - - - Rome and the day before sparqling - - - - - - Sparqling days in Monte Sansavino - - - - - - More Sparqling fun - - - - - - post sparql-relaxation - - - - - - Sightseeing - Sienna - - - - - - Via Cassia to Rome - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-literals-test001.rdf ---------------------------------------------------------------------- diff --git a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-literals-test001.rdf b/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-literals-test001.rdf deleted file mode 100644 index 433df3c..0000000 --- a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-literals-test001.rdf +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test001.rdf ---------------------------------------------------------------------- diff --git a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test001.rdf b/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test001.rdf deleted file mode 100644 index 038a7ac..0000000 --- a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test001.rdf +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - 2000 - - http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test002.rdf ---------------------------------------------------------------------- diff --git a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test002.rdf b/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test002.rdf deleted file mode 100644 index 7d83d5e..0000000 --- a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/rdf-charmod-uris-test002.rdf +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - 2000 - - http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/xml-canon-test001.rdf ---------------------------------------------------------------------- diff --git a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/xml-canon-test001.rdf b/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/xml-canon-test001.rdf deleted file mode 100644 index 884fa22..0000000 --- a/rdf.stable.serializer/src/test/resources/org/apache/clerezza/rdf/stable/serializer/xml-canon-test001.rdf +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - -
-
- -
- http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/pom.xml ---------------------------------------------------------------------- diff --git a/rdf/pom.xml b/rdf/pom.xml index de62088..ca3d6f7 100644 --- a/rdf/pom.xml +++ b/rdf/pom.xml @@ -53,6 +53,7 @@ ontologies rdfa simple.storage + stable.serializer storage.web file.storage utils http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/LICENSE ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/LICENSE b/rdf/stable.serializer/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/rdf/stable.serializer/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/pom.xml ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/pom.xml b/rdf/stable.serializer/pom.xml new file mode 100644 index 0000000..317e892 --- /dev/null +++ b/rdf/stable.serializer/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + clerezza + org.apache.clerezza + 7-SNAPSHOT + + + org.apache.clerezza + rdf.stable.serializer + bundle + 1.0.0-SNAPSHOT + Clerezza - RDF Stable Serializer + A SerializingProvider that prodocues a stable output. This means + if the graph to be serialized changes a little, then also the output + changes a little. + + + org.apache.clerezza.commons-rdf + commons-rdf-api + 0.1 + + + org.apache.clerezza + rdf.core + 1.0.0-SNAPSHOT + + + org.apache.felix + org.apache.felix.scr.annotations + + + org.apache.clerezza + rdf.jena.serializer + test + 1.0.0-SNAPSHOT + + + org.apache.clerezza + rdf.jena.parser + test + 1.0.0-SNAPSHOT + + + org.apache.clerezza + rdf.utils + 1.0.0-SNAPSHOT + + + junit + junit + test + + + commons-lang + commons-lang + 2.6 + test + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializer.java ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializer.java b/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializer.java new file mode 100644 index 0000000..0342bf6 --- /dev/null +++ b/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializer.java @@ -0,0 +1,184 @@ +/* + * 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.stable.serializer; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.HashMap; + +import org.apache.clerezza.commons.rdf.BlankNode; +import org.apache.clerezza.commons.rdf.Literal; +import org.apache.clerezza.commons.rdf.Triple; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.rdf.ontologies.XSD; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A serializer that can serialze RDF Graphs into N-Triples format. + * + * NOTE: This is a special purpose serializer to be used with + * {@link org.apache.clerezza.rdf.stable.serializer.StableSerializerProvider}. + * Instances are assumed to be short-lived and not used concurrently. + * + * @author Daniel Spicar (daniel.spicar@access.uzh.ch) + */ +class NTriplesSerializer { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + private long genSymCounter = 0; + private HashMap bNodeLabels; + + /** + * Resets the counter to zero that constitutes + * the numerical part of blank node labels. + */ + void resetGenSymCounter() { + genSymCounter = 0; + } + + /** + * Serializes a given Graph using the N-Triples format. + * + * @param os + * An outputstream. + * @param tc + * the triples of the graph to be serialized. + */ + void serialize(OutputStream os, Graph tc) { + try { + bNodeLabels = new HashMap(tc.size() / 2); + + for (Triple t : tc) { + if (t.getSubject() instanceof BlankNode) { + os.write(serializeBlankNode((BlankNode) t.getSubject()).getBytes()); + } else { + os.write(serializeIRI( + (IRI) t.getSubject()).getBytes()); + } + + os.write((t.getPredicate().toString() + " ").getBytes()); + + if (t.getObject() instanceof BlankNode) { + os.write(serializeBlankNode((BlankNode) t.getObject()).getBytes()); + os.write(".\n".getBytes()); + } else { + if (t.getObject() instanceof Literal) { + os.write((serializeLiteral((Literal) t.getObject()) + + ".\n").getBytes()); + } else { + os.write((serializeIRI((IRI) t.getObject()) + + ".\n").getBytes()); + } + } + } + } catch (IOException ex) { + logger.error("Exception while serializing graph: {}", ex); + } + } + + private String serializeIRI(IRI uriRef) { + StringBuffer sb = new StringBuffer("<"); + escapeUtf8ToUsAscii(uriRef.getUnicodeString(), sb, true); + sb.append("> "); + + return sb.toString() ; + } + + private String serializeBlankNode(BlankNode bNode) { + if (bNodeLabels.containsKey(bNode)) { + return bNodeLabels.get(bNode) + " "; + } else { + String label = "_:b" + genSymCounter++; + bNodeLabels.put(bNode, label); + return label + " "; + } + } + + private String serializeLiteral(Literal literal) { + StringBuffer sb = new StringBuffer("\""); + escapeUtf8ToUsAscii(literal.getLexicalForm(), sb, false); + sb = sb.append("\""); + + if(literal.getDataType().equals(XSD.string)) { + if(literal.getLanguage() != null && + !literal.getLanguage().toString().equals("")) { + + sb.append("@"); + sb.append(literal.getLanguage().toString()); + } + } else { + sb.append("^^<"); + escapeUtf8ToUsAscii( + literal.getDataType().getUnicodeString(), sb, false); + sb.append(">"); + } + + sb.append(" "); + + return sb.toString() ; + } + + private void escapeUtf8ToUsAscii(String input, StringBuffer sb, boolean uri) { + + for (int i = 0; i < input.length(); ++i) { + char c = input.charAt(i); + int val = (int) c; + if (c == '\t') { + sb.append("\\t"); + } else if (c == '\n') { + sb.append("\\n"); + } else if (c == '\r') { + sb.append("\\r"); + } else if (c == '"') { + sb.append("\\\""); + } else if (c == '\\') { + sb.append("\\\\"); + } else if ((val >= 0x0 && val <= 0x8) || (val >= 0xB && val <= 0xC) + || (val >= 0xE && val <= 0x1F) + || (val >= 0x7F && val <= 0xFFFF)) { + sb.append("\\u"); + sb.append(getIntegerHashString(val, 4)); + } else if (val >= 0x10000 && val <= 0x10FFFF) { + sb.append("\\U"); + sb.append(getIntegerHashString(val, 8)); + } else { + if (uri && (c == '>' || c == '<')) { + sb.append("\\u"); + sb.append(getIntegerHashString(val, 4)); + } else { + sb.append(c); + } + } + } + } + + private String getIntegerHashString(int val, int length) { + StringBuffer sb = new StringBuffer(); + String hex = Integer.toHexString(val); + for(int i = 0; i < length - hex.length(); ++i) { + sb.append("0"); + } + sb.append(hex); + + return sb.toString().toUpperCase(); + } +} http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerProvider.java ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerProvider.java b/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerProvider.java new file mode 100644 index 0000000..f25c5d3 --- /dev/null +++ b/rdf/stable.serializer/src/main/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerProvider.java @@ -0,0 +1,468 @@ +/* + * 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.stable.serializer; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.StringReader; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.clerezza.commons.rdf.BlankNode; +import org.apache.clerezza.commons.rdf.ImmutableGraph; +import org.apache.clerezza.commons.rdf.Literal; +import org.apache.clerezza.commons.rdf.RDFTerm; +import org.apache.clerezza.commons.rdf.Triple; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph; +import org.apache.clerezza.rdf.core.serializedform.SerializingProvider; +import org.apache.clerezza.rdf.core.serializedform.SupportedFormat; +import org.apache.clerezza.rdf.utils.GraphNode; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.ComponentContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/* + * Credits: + * + * Blank node labeling algorithm by Jeremy J. Carroll (see "Signing RDF Graphs", + * HP technical report 2003) + * + * Minimum Self-contained ImmutableGraph (MSG) decomposition algorithm by + * Giovanni Tummarello, Christian Morbidoni, Paolo Puliti, Francesco Piazza, + * Università Politecnica delle Marche, Italy + * (see "Signing individual fragments of an RDF graph", 14th International + * World Wide Web Conference WWW2005, Poster track, May 2005, Chiba, Japan) + */ + +/** + * A {@link org.apache.clerezza.rdf.core.serializedform.SerializingProvider} that tries + * to provide similar results when serializing graphs. Specifically it tries to + * label blank nodes deterministically with reasonable complexity. + * + * This serializer does not guarantee a deterministic result but it may minimize + * the amount of modified lines in serialized output. + * + * @author Daniel Spicar (daniel.spicar@access.uzh.ch) + */ +@Component +@Service(SerializingProvider.class) +@SupportedFormat({SupportedFormat.N_TRIPLE}) +public class StableSerializerProvider implements SerializingProvider { + + @Property(description="Specifies maximum amount of blank nodes " + + "labeling recursions, may increase performance at the expense of stability " + + "(0 = no limit).", intValue=0) + public static final String MAX_LABELING_ITERATIONS = "max_labeling_iterations"; + + private int maxLabelingIterations = -1; + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + protected void activate(ComponentContext cCtx) { + maxLabelingIterations = (Integer) cCtx.getProperties(). + get(MAX_LABELING_ITERATIONS); + logger.info("StableSerializerProvider activated"); + } + + @Override + public void serialize(OutputStream os, Graph tc, + String formatIdentifier) { + + try { + List lines = new LinkedList(); + List msgs = decomposeGraphToMSGs(tc); + NTriplesSerializer serializer = new NTriplesSerializer(); + + computeMsgHashes(msgs, "MD5"); + + for (MSG msg : msgs) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + serializer.serialize(baos, msg.tc); + BufferedReader serializedGraph = + new BufferedReader(new StringReader(baos.toString())); + lines.addAll(labelBlankNodes(serializedGraph, msg.hash)); + } + + Collections.sort(lines); + for (String l : lines) { + os.write((l + "\n").getBytes()); + } + } catch (IOException ex) { + logger.error("Exception while parsing serialized graph: {}", ex); + } catch (NoSuchAlgorithmException ex) { + logger.error("Exception while trying to generate graph hash: {}", ex); + } + } + + private List decomposeGraphToMSGs(Graph tc) { + + Graph tmp = new SimpleGraph(); + tmp.addAll(tc); + + List msgSet = new LinkedList(); + + while (tmp.size() > 0) { + Triple triple = tmp.iterator().next(); + Graph msgTc = new SimpleGraph(); + + boolean containsBlankNode = fillMSG(triple, tmp, msgTc); + MSG msg = new MSG(msgTc); + msg.containsBlankNodes = containsBlankNode; + msgSet.add(msg); + } + + return msgSet; + } + + private boolean fillMSG(Triple triple, Graph tc, + Graph msg) { + + boolean containsBlankNode = false; + + RDFTerm resource = triple.getSubject(); + if (resource instanceof BlankNode) { + containsBlankNode = true; + } else { + resource = triple.getObject(); + if (resource instanceof BlankNode) { + containsBlankNode = true; + } + } + if (containsBlankNode) { + GraphNode gn = new GraphNode(resource, tc); + ImmutableGraph context = gn.getNodeContext(); + msg.addAll(context); + tc.removeAll(context); + } else { + msg.add(triple); + tc.remove(triple); + } + return containsBlankNode; + } + + private List labelBlankNodes(BufferedReader serializedGraph, + String prefix) throws IOException { + + String line = null; + List lines = new LinkedList(); + + long commentedIdentifiers = 0; + while ((line = serializedGraph.readLine()) != null) { + try { + commentedIdentifiers = commentBlankNodeLabels(line, + commentedIdentifiers, lines); + } catch (IOException ex) { + logger.error("Exception while trying to parse line: " + + line + "\n{}", ex); + } + } + + Collections.sort(lines); + + Map labels = new HashMap(); + long[] counters = {1, commentedIdentifiers}; //counter[0] = genSymCounter + long commentedIdentifierBefore; + int ctr = 0; + do { + commentedIdentifierBefore = counters[1]; + counters = generateBlankNodeLabels(lines, labels, counters[0], + counters[1], prefix); + applyLabels(lines, labels, prefix); + Collections.sort(lines); + if(++ctr == maxLabelingIterations) { + break; + } + } while (counters[1] > 0 && commentedIdentifierBefore != counters[1]); + + if (counters[1] > 0) { + labelBlankNodesNonDeterministically(lines, counters, labels, prefix); + } + + return lines; + } + + + private long[] generateBlankNodeLabels(List lines, + Map labels, long genSymCounter, long comments, + String prefix) { + + for (int i = 1; i <= lines.size(); ++i) { + StringBuilder previousLine = i > 1 ?new StringBuilder(lines.get(i - 2)) : new StringBuilder(); + StringBuilder currentLine = new StringBuilder(lines.get(i - 1)); + StringBuilder nextLine = new StringBuilder(); + if (i < lines.size()) { + nextLine.append(lines.get(i)); + } + + String currentLineWithoutComments = stripComments(currentLine); + if (stripComments(previousLine).equals(currentLineWithoutComments) || + stripComments(nextLine).equals(currentLineWithoutComments)) { + continue; + } + + int indexOfObject = checkObject(currentLineWithoutComments); + if (indexOfObject != -1) { + genSymCounter = applyGenSymIdentifier(labels, genSymCounter, + currentLine, indexOfObject, prefix); + --comments; + } + + int indexOfSubject = checkSubject(currentLineWithoutComments); + if (indexOfSubject != -1) { + genSymCounter = applyGenSymIdentifier(labels, genSymCounter, + currentLine, indexOfSubject, prefix); + --comments; + } + + lines.set(i - 1, currentLine.toString()); + } + + long[] result = {genSymCounter, comments}; + return result; + } + + private void applyLabels(List lines, Map labels, + String prefix) { + + for (int i = 0; i < lines.size(); ++i) { + StringBuilder line = new StringBuilder(lines.get(i)); + + int indexOfObject = checkObject(stripComments(line)); + if (indexOfObject != -1) { + int indexOfComment = line.lastIndexOf("#_:"); + String identifier = + line.substring(indexOfComment + 1, line.length()); + + if (labels.containsKey(identifier)) { + line.delete(indexOfComment, line.length()); + line.delete(indexOfObject, indexOfObject + 1); + line.insert(indexOfObject, "_:" + prefix + + labels.get(identifier)); + } + } + + int indexOfSubject = checkSubject(stripComments(line)); + if (indexOfSubject != -1) { + int indexOfComment = line.lastIndexOf("#_:"); + String identifier = + line.substring(indexOfComment + 1, line.length()); + + if (labels.containsKey(identifier)) { + line.delete(indexOfComment, line.length()); + line.delete(indexOfSubject, indexOfSubject + 1); + line.insert(indexOfSubject, "_:" + prefix + + labels.get(identifier)); + } + } + + lines.set(i, line.toString()); + } + } + + private long commentBlankNodeLabels(String line, long commentedIdentifiers, + List lines) throws IOException { + + StringReader lineReader = new StringReader(line); + int data = lineReader.read(); + while (data != -1) { + if (data == '<') { + //skip until end tag + while ((data = lineReader.read()) != '>') { + checkForEndOfStream(data); + } + } else if (data == '"') { + break; + } else if (data == '_') { + if ((data = lineReader.read()) == ':') { + String identifier = "_:"; + while ((data = lineReader.read()) != ' ') { + checkForEndOfStream(data); + identifier = identifier.concat( + Character.toString((char) data)); + } + line = line.replaceFirst(identifier, "~"); + line = line.concat(" #" + identifier); + ++commentedIdentifiers; + checkForEndOfStream(data); + } + } + data = lineReader.read(); + } + lines.add(line); + return commentedIdentifiers; + } + + private long applyGenSymIdentifier(Map labels, + long genSymCounter, StringBuilder currentLine, int where, + String prefix) { + + int index = currentLine.lastIndexOf("#_:"); + String identifier = + currentLine.substring(index + 1, currentLine.length()).trim(); + currentLine.delete(index, currentLine.length()); + if (!labels.containsKey(identifier)) { + labels.put(identifier, genSymCounter++); + } + currentLine.delete(where, where + 1); + currentLine.insert(where, "_:" + prefix + labels.get(identifier)); + + return genSymCounter; + } + + private void labelBlankNodesNonDeterministically(List lines, + long[] counters, Map labels, String prefix) { + + for (int i = 0; i < lines.size(); ++i) { + StringBuilder currentLine = new StringBuilder(lines.get(i)); + String currentLineWithoutComments = stripComments(currentLine); + int indexOfObject = checkObject(currentLineWithoutComments); + if (indexOfObject != -1) { + counters[0] = applyGenSymIdentifier(labels, counters[0], + currentLine, indexOfObject, prefix); + --(counters[1]); + } + int indexOfSubject = checkSubject(currentLineWithoutComments); + if (indexOfSubject != -1) { + counters[0] = applyGenSymIdentifier(labels, counters[0], + currentLine, indexOfSubject, prefix); + --(counters[1]); + } + lines.set(i, currentLine.toString()); + } + Collections.sort(lines); + } + + private void checkForEndOfStream(int data) throws IOException { + if (data == -1) { + throw new IOException("Parsing Error!"); + } + } + + private int checkObject(String line) { + int index = -1; + if (line.charAt((index = line.length() - 3)) == '~') { + return index; + } + return -1; + } + + private int checkSubject(String line) { + if (line.charAt(0) == '~') { + return 0; + } + return -1; + } + + + private String stripComments(StringBuilder line) { + if (line.length() < 3) { + return ""; + } + return line.substring(0, line.lastIndexOf(" .") + 2); + } + + private void computeMsgHashes(List msgs, String algorithm) + throws NoSuchAlgorithmException { + + MessageDigest md = MessageDigest.getInstance(algorithm); + HashSet computedHashes = new HashSet(msgs.size()); + + for(MSG msg : msgs) { + if(!msg.containsBlankNodes) { + //hash is needed only for b-node labelling + continue; + } + List tripleHashes = new ArrayList(msg.tc.size()); + for (Triple t : msg.tc) { + StringBuilder tripleHash = new StringBuilder(); + if (!(t.getSubject() instanceof BlankNode)) { + tripleHash.append(((IRI) t.getSubject()).hashCode()); + } + tripleHash.append(t.getPredicate().hashCode()); + if (!(t.getObject() instanceof BlankNode)) { + if (t.getObject() instanceof Literal) { + tripleHash.append(((Literal) t.getObject()). + toString().hashCode()); + } else { + tripleHash.append(((IRI) t.getObject()).hashCode()); + } + } + tripleHashes.add(tripleHash.toString()); + } + Collections.sort(tripleHashes); + StringBuilder msgHash = new StringBuilder(); + for(String tripleHash : tripleHashes) { + msgHash.append(tripleHash); + } + + md.update(msgHash.toString().getBytes()); + + String hexString; + if(computedHashes.add((hexString = getHashHexString(md.digest())))){ + msg.hash = hexString; + } else { + md.update(String.valueOf( + System.currentTimeMillis()).getBytes()); + while(!computedHashes.add( + (hexString = getHashHexString(md.digest())))) { + md.update(String.valueOf( + System.currentTimeMillis()).getBytes()); + } + msg.hash = hexString; + } + } + } + + private String getHashHexString(byte[] hash) { + StringBuilder hexString = new StringBuilder(); + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xFF & hash[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + } + + private static class MSG { + + final Graph tc; + String hash = null; + boolean containsBlankNodes = false; + + MSG(Graph tc) { + this.tc = tc; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.serializedform.SerializingProvider ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.serializedform.SerializingProvider b/rdf/stable.serializer/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.serializedform.SerializingProvider new file mode 100644 index 0000000..8a9b397 --- /dev/null +++ b/rdf/stable.serializer/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.serializedform.SerializingProvider @@ -0,0 +1 @@ +org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/DocumentationStabilityTest.java ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/DocumentationStabilityTest.java b/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/DocumentationStabilityTest.java new file mode 100644 index 0000000..5f511fa --- /dev/null +++ b/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/DocumentationStabilityTest.java @@ -0,0 +1,66 @@ +/* + * 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.stable.serializer; + +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.apache.clerezza.commons.rdf.ImmutableGraph; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.IRI; +import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph; +import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl; +import org.apache.clerezza.rdf.core.serializedform.Parser; +import org.apache.clerezza.rdf.core.serializedform.SupportedFormat; +import org.junit.Assert; +import org.junit.Test; + + +public class DocumentationStabilityTest { + + @Test + public void RDFTestCases() throws Exception { + + Parser parser = Parser.getInstance(); + ImmutableGraph tc1 = parser.parse( + getClass().getResourceAsStream("documentation-example.nt"), SupportedFormat.N_TRIPLE); + final Set lines1 = serializeToLines(tc1); + Graph tc2 = new SimpleGraph(); + tc2.addAll(tc1); + //add . + tc2.add(new TripleImpl(new IRI("bundle:///intro"), + new IRI("http://clerezza.org/2009/08/documentation#after"), + new IRI("bundle://org.apache.clerezza.platform.documentation/intro"))); + final Set lines2 = serializeToLines(tc2); + lines2.removeAll(lines1); + Assert.assertEquals(1, lines2.size()); + } + + private Set serializeToLines(Graph tc) throws UnsupportedEncodingException { + StableSerializerProvider ssp = new StableSerializerProvider(); + final ByteArrayOutputStream os1 = new ByteArrayOutputStream(); + ssp.serialize(os1, tc, SupportedFormat.N_TRIPLE); + return new HashSet(Arrays.asList(new String(os1.toByteArray(), "utf-8").split("\n"))); + + } + +} http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializerTest.java ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializerTest.java b/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializerTest.java new file mode 100644 index 0000000..b3d3292 --- /dev/null +++ b/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/NTriplesSerializerTest.java @@ -0,0 +1,91 @@ +/* + * 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.stable.serializer; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.Arrays; +import java.util.Collection; + +import junit.framework.Assert; + +import org.apache.clerezza.commons.rdf.ImmutableGraph; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph; +import org.apache.clerezza.rdf.core.serializedform.Parser; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * + * @author daniel + */ +@RunWith(Parameterized.class) +public class NTriplesSerializerTest { + + private String inputFileName; + private String format; + + public NTriplesSerializerTest(String inputFileName, String format) { + this.inputFileName = inputFileName; + this.format = format; + } + + @Parameterized.Parameters + public static Collection inputFileNames() { + return Arrays.asList(new String[][] { + {"amp-in-url-test001.rdf", "application/rdf+xml"}, + {"datatypes-test001.rdf", "application/rdf+xml"}, + {"datatypes-test002.rdf", "application/rdf+xml"}, + {"rdf-charmod-literals-test001.rdf", "application/rdf+xml"}, + {"rdf-charmod-uris-test001.rdf", "application/rdf+xml"}, + {"rdf-charmod-uris-test002.rdf", "application/rdf+xml"}, + {"xml-canon-test001.rdf", "application/rdf+xml"}, + {"css3deps.rdf", "application/rdf+xml"}, + {"agenda_62.rdf", "application/rdf+xml"}, + {"Talks.rdf", "application/rdf+xml"}, + {"elvisimp.rdf", "application/rdf+xml"}, + //{"images.xrdf", "application/rdf+xml"}, //large + {"libby.foaf", "application/rdf+xml"} + }); + } + + @Test + public void RDFTestCases() { + NTriplesSerializer nts = new NTriplesSerializer(); + + Parser parser = Parser.getInstance(); + ImmutableGraph deserializedGraphOld = parser.parse( + getClass().getResourceAsStream(inputFileName), format); + + Graph tc = new SimpleGraph(); + tc.addAll(deserializedGraphOld); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + nts.serialize(baos, tc); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + + ImmutableGraph deserializedGraphNew = parser.parse(bais, "application/n-triples"); + + Assert.assertEquals(deserializedGraphNew, deserializedGraphOld); + } + +} http://git-wip-us.apache.org/repos/asf/clerezza/blob/d7fb079c/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerGraphTest.java ---------------------------------------------------------------------- diff --git a/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerGraphTest.java b/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerGraphTest.java new file mode 100644 index 0000000..2637f8d --- /dev/null +++ b/rdf/stable.serializer/src/test/java/org/apache/clerezza/rdf/stable/serializer/StableSerializerGraphTest.java @@ -0,0 +1,89 @@ +/* + * 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.stable.serializer; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.Arrays; +import java.util.Collection; + +import org.apache.clerezza.commons.rdf.ImmutableGraph; +import org.apache.clerezza.commons.rdf.Graph; +import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph; +import org.apache.clerezza.rdf.core.serializedform.Parser; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * + * @author daniel + */ +@RunWith(Parameterized.class) +public class StableSerializerGraphTest { + private String inputFileName; + private String format; + + public StableSerializerGraphTest(String inputFileName, String format) { + this.inputFileName = inputFileName; + this.format = format; + } + + @Parameterized.Parameters + public static Collection inputFileNames() { + return Arrays.asList(new String[][]{ + {"amp-in-url-test001.rdf", "application/rdf+xml"}, + {"datatypes-test001.rdf", "application/rdf+xml"}, + {"datatypes-test002.rdf", "application/rdf+xml"}, + {"rdf-charmod-literals-test001.rdf", "application/rdf+xml"}, + {"rdf-charmod-uris-test001.rdf", "application/rdf+xml"}, + {"rdf-charmod-uris-test002.rdf", "application/rdf+xml"}, + {"xml-canon-test001.rdf", "application/rdf+xml"}, + {"css3deps.rdf", "application/rdf+xml"}, + {"agenda_62.rdf", "application/rdf+xml"}, + {"Talks.rdf", "application/rdf+xml"}, + {"elvisimp.rdf", "application/rdf+xml"}, + //{"images.xrdf", "application/rdf+xml"}, //large + {"libby.foaf", "application/rdf+xml"} + }); + } + + @Test + public void RDFTestCases() { + StableSerializerProvider ssp = new StableSerializerProvider(); + + Parser parser = Parser.getInstance(); + ImmutableGraph deserializedGraphOld = parser.parse( + getClass().getResourceAsStream(inputFileName), format); + + Graph tc = new SimpleGraph(); + tc.addAll(deserializedGraphOld); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ssp.serialize(baos, tc, "application/n-triples"); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + + ImmutableGraph deserializedGraphNew = parser.parse(bais, "application/n-triples"); + + Assert.assertEquals(deserializedGraphOld, deserializedGraphNew); + + } +}