1 5 6 package com.hp.hpl.jena.rdql.parser; 7 8 9 import java.io.PrintWriter ; 10 import com.hp.hpl.jena.graph.query.IndexValues ; 11 import com.hp.hpl.jena.graph.query.Expression ; 12 import com.hp.hpl.jena.rdql.*; 13 14 import org.apache.oro.text.regex.* ; 16 19 20 public class Q_StringNoMatch extends ExprNode implements Expr, ExprBoolean 21 { 22 Expr left ; 23 Expr right ; 24 Q_PatternLiteral regex = null ; 25 PatternCompiler compiler = new Perl5Compiler(); 27 PatternMatcher matcher = new Perl5Matcher(); 28 29 31 private String printName = "strMatch" ; 32 private String opSymbol = "!~" ; 33 Pattern pattern = null ; 34 35 Q_StringNoMatch(int id) 36 { super(id); } 37 38 Q_StringNoMatch(RDQLParser p, int id) 39 { super(p, id); } 40 41 42 public NodeValue eval(Query q, IndexValues env) 43 { 44 51 NodeValue x = left.eval(q, env) ; 52 54 56 String xx = x.valueString() ; 57 60 NodeValueSettable result = new WorkingVar() ; 61 62 boolean b = matcher.contains(xx, pattern) ; 64 result.setBoolean(!b) ; 65 return result ; 66 } 67 68 71 public boolean isApply() { return true ; } 72 public String getFun() { return super.constructURI(this.getClass().getName()) ; } 73 public int argCount() { return 2; } 74 public Expression getArg(int i) 75 { 76 if ( i == 0 && left instanceof Expression ) 77 return (Expression)left ; 78 if ( i == 1 && right instanceof Expression ) 79 return (Expression)right ; 80 return null; 81 } 82 public void jjtClose() 83 { 84 int n = jjtGetNumChildren() ; 85 if ( n != 2 ) 86 throw new QueryException("Q_StringNoMatch: Wrong number of children: "+n) ; 87 88 left = (Expr)jjtGetChild(0) ; 89 right = (Expr)jjtGetChild(1) ; if ( ! ( right instanceof Q_PatternLiteral ) ) 91 throw new EvalFailureException("Q_StringNoMatch: Pattern error") ; 92 93 regex = (Q_PatternLiteral)right ; 94 95 try 96 { 97 pattern = compiler.compile(regex.patternString, regex.mask) ; 98 } catch (MalformedPatternException pEx) 99 { 100 throw new EvalFailureException("Q_StringNoMatch: Pattern exception: "+pEx) ; 101 } 102 } 103 104 public String asInfixString() 105 { 106 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 107 } 108 109 public String asPrefixString() 110 { 111 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 112 } 113 114 public void print(PrintWriter pw, int level) 115 { 116 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 117 } 118 119 public String toString() 120 { 121 return asInfixString() ; 122 } 123 } 124 150 | Popular Tags |