1 6 7 package com.hp.hpl.jena.graph.query; 8 9 import com.hp.hpl.jena.graph.*; 10 11 18 public final class PatternStageCompiler implements PatternCompiler 19 { 20 22 public PatternStageCompiler() 23 {} 24 25 29 public static Pattern [] compile( PatternCompiler compiler, Mapping map, Triple [] source ) 30 { 31 Pattern [] compiled = new Pattern[source.length]; 32 for (int i = 0; i < source.length; i += 1) compiled[i] = compile( compiler, source[i], map ); 33 return compiled; 34 } 35 36 39 private static Pattern compile( PatternCompiler compiler, Triple t, Mapping map ) 40 { 41 Node S = t.getSubject(), P = t.getPredicate(), O = t.getObject(); 42 return new Pattern( compile( compiler, S, map ), compile( compiler, P, map ), compile( compiler, O, map ) ); 43 } 44 45 51 private static Element compile( PatternCompiler compiler, Node X, Mapping map ) 52 { 53 if (X.equals( Query.ANY )) return compiler.any(); 54 if (X.isVariable()) 55 { 56 if (map.hasBound( X )) 57 return compiler.bound( X, map.indexOf( X ) ); 58 else 59 return compiler.bind( X, map.newIndex( X ) ); 60 } 61 return compiler.fixed( X ); 62 } 63 64 67 public Element fixed( Node value ) 68 { return new Fixed( value ); } 69 70 public Element bound( Node n, int index ) 71 { return new Bound( index ); } 72 73 public Element bind( Node n, int index ) 74 { return new Bind( index ); } 75 76 public Element any() 77 { return Element.ANY; } 78 } 79 | Popular Tags |