01: /*
02: (c) Copyright 2008 Hewlett-Packard Development Company, LP
03: All rights reserved.
04: $Id: TestMultiUnionReifier.java,v 1.1 2008/02/12 09:32:02 chris-dollin Exp $
05: */
06:
07: package com.hp.hpl.jena.graph.compose.test;
08:
09: import com.hp.hpl.jena.graph.*;
10: import com.hp.hpl.jena.graph.compose.MultiUnion;
11: import com.hp.hpl.jena.graph.test.NodeCreateUtils;
12: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
13: import com.hp.hpl.jena.shared.ReificationStyle;
14: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
15:
16: /**
17: Test the reifier for multi-unions.
18:
19: @author kers
20: */
21: public class TestMultiUnionReifier extends ModelTestBase {
22: public TestMultiUnionReifier(String name) {
23: super (name);
24: }
25:
26: public void testX() {
27: MultiUnion mu = multi("a P b; !b Q c; ~c R d", "");
28: for (ExtendedIterator it = GraphUtil.findAll(mu); it.hasNext();) {
29: System.err.println("]] " + it.next());
30: }
31: }
32:
33: private MultiUnion multi(String a, String b) {
34: Graph A = graph(a), B = graph(b);
35: return new MultiUnion(new Graph[] { A, B });
36: }
37:
38: static int count = 0;
39:
40: private Graph graph(String facts) {
41: Graph result = Factory
42: .createDefaultGraph(ReificationStyle.Standard);
43: String[] factArray = facts.split(";");
44: for (int i = 0; i < factArray.length; i += 1) {
45: String fact = factArray[i].trim();
46: if (fact.equals("")) {
47: } else if (fact.charAt(0) == '!') {
48: Triple t = Triple.create(fact.substring(1));
49: result.add(t);
50: result.getReifier().reifyAs(
51: NodeCreateUtils.create("_r" + ++count), t);
52: } else if (fact.charAt(0) == '~') {
53: Triple t = Triple.create(fact.substring(1));
54: result.getReifier().reifyAs(
55: NodeCreateUtils.create("_r" + ++count), t);
56: } else
57: result.add(Triple.create(fact));
58: }
59: return result;
60: }
61: }
|