Project

General

Profile

« Previous | Next » 

Revision 50782

Testing RDF XML serialization

View differences:

modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/ExampleIO_01.java
1
package eu.dnetlib.parthenos.virtuoso;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5

  
6
import org.apache.jena.rdf.model.Model;
7
import org.apache.jena.rdf.model.ModelFactory;
8
import org.apache.jena.riot.RDFDataMgr;
9
import org.apache.jena.riot.RDFFormat;
10
import org.apache.jena.riot.RIOT;
11
import org.junit.Test;
12
import org.springframework.core.io.ClassPathResource;
13

  
14
/**
15
 * Licensed to the Apache Software Foundation (ASF) under one
16
 * or more contributor license agreements.  See the NOTICE file
17
 * distributed with this work for additional information
18
 * regarding copyright ownership.  The ASF licenses this file
19
 * to you under the Apache License, Version 2.0 (the
20
 * "License"); you may not use this file except in compliance
21
 * with the License.  You may obtain a copy of the License at
22
 * <p>
23
 * http://www.apache.org/licenses/LICENSE-2.0
24
 * <p>
25
 * Unless required by applicable law or agreed to in writing, software
26
 * distributed under the License is distributed on an "AS IS" BASIS,
27
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
 * See the License for the specific language governing permissions and
29
 * limitations under the License.
30
 */
31

  
32
public class ExampleIO_01 {
33

  
34
	@Test
35
		public void test() throws IOException {
36
			InputStream in = getResourceAsStream("eu/dnetlib/parthenos/virtuoso/data.ttl");
37

  
38
			RIOT.init() ;
39

  
40
			Model model = ModelFactory.createDefaultModel(); // creates an in-memory Jena Model
41
			model.read(in, null, "TURTLE"); // parses an InputStream assuming RDF in Turtle format
42

  
43
			// Write the Jena Model in Turtle, RDF/XML and N-Triples format
44
			System.out.println("\n---- Turtle ----");
45
			model.write(System.out, "TURTLE");
46
			System.out.println("\n---- RDF/XML ----");
47
			model.write(System.out, "RDF/XML");
48
			System.out.println("\n---- RDF/XML Abbreviated ----");
49
			model.write(System.out, "RDF/XML-ABBREV");
50
			System.out.println("\n---- N-Triples ----");
51
			model.write(System.out, "N-TRIPLES");
52
			System.out.println("\n---- RDF/JSON ----");
53
			model.write(System.out, "RDF/JSON");
54
			System.out.println("\n---- RDF/XML_PLAIN ----");
55
			model.write(System.out, "RDF/XML_PLAIN");
56
			System.out.println("\n----RDFDataMgr with graph and RDFFormat.RDFXML_PLAIN ----");
57
			RDFDataMgr.write(System.out, model.getGraph(), RDFFormat.RDFXML_PLAIN);
58
			System.out.println("\n----RDFDataMgr with model and RDFFormat.RDFXML_PLAIN ----");
59
			RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_PLAIN);
60

  
61

  
62
		}
63

  
64

  
65
	private InputStream getResourceAsStream(final String classpath) throws IOException {
66
		final ClassPathResource resource = new ClassPathResource(classpath);
67
		return resource.getInputStream();
68
	}
69

  
70
}
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoTest.java
153 153
		long size = md.size();
154 154
		System.out.println("==Inserted " + size + "triples==");
155 155

  
156
//		System.out.println("*************RDF/XML*************");
157
//		md.write(System.out, "RDF/XML");
158

  
159
//		System.out.println("*************RDF/XML-ABBREV*************");
160
//		md.write(System.out, "RDF/XML-ABBREV");
161

  
162
//		System.out.println("*************Default language*************");
163
//		md.write(System.out);
164

  
165
		md.write(System.out, "RDF/XML");
166

  
156 167
		VirtGraph graph = new VirtGraph(testGraph, connectionString, testUser, testPwd);
157 168
		assertNotNull(graph);
158 169
		Assert.assertFalse(graph.isEmpty());
modules/dnet-parthenos-publisher/trunk/test/main/resources/eu/dnetlib/parthenos/virtuoso/data.ttl
1
@prefix : <http://example.org/> .
2
@prefix foaf:   <http://xmlns.com/foaf/0.1/> .
3

  
4
:alice
5
    a           foaf:Person ;
6
    foaf:name   "Alice" ;
7
    foaf:mbox   <mailto:alice@example.org> ;
8
    foaf:knows  :bob ;
9
    foaf:knows  :charlie ;
10
    foaf:knows  :snoopy ;
11
    .
12

  
13
:bob
14
    foaf:name   "Bob" ;
15
    foaf:knows  :charlie ;
16
    .
17

  
18
:charlie
19
    foaf:name   "Charlie" ;
20
    foaf:knows  :alice ;
21
    .

Also available in: Unified diff