TestConstraints.java
0001 /*
0002  *  TestConstraints
0003  *
0004  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
0005  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
0006  *
0007  *  This file is part of GATE (see http://gate.ac.uk/), and is free
0008  *  software, licenced under the GNU Library General Public License,
0009  *  Version 2, June 1991 (in the distribution as file licence.html,
0010  *  and also available at http://gate.ac.uk/gate/licence.html).
0011  *
0012  *  Eric Sword, 03/09/08
0013  *
0014  *  $Id$
0015  */
0016 package gate.jape.functest;
0017 
0018 import gate.Annotation;
0019 import gate.AnnotationSet;
0020 import gate.Document;
0021 import gate.Factory;
0022 import gate.FeatureMap;
0023 import gate.jape.Transducer;
0024 import gate.jape.parser.ParseCpsl;
0025 import gate.jape.parser.ParseException;
0026 import gate.util.InvalidOffsetException;
0027 import gate.util.Out;
0028 
0029 import java.io.StringReader;
0030 import java.util.HashMap;
0031 import java.util.Set;
0032 
0033 import junit.extensions.TestSetup;
0034 import junit.framework.Test;
0035 import junit.framework.TestSuite;
0036 
0037 import org.apache.log4j.Logger;
0038 
0039 /**
0040  * Tests for Constraint predicate logic
0041  */
0042 public class TestConstraints extends BaseJapeTests {
0043   private static final Logger logger = Logger.getLogger(TestConstraints.class);
0044 
0045   public TestConstraints(String name) {
0046     super(name);
0047   }
0048 
0049   /**
0050    * Try to transduce on empty document
0051    */
0052   public void test000TransduceEmptyDoc() throws Exception {
0053     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.1.jape";
0054     Set<Annotation> actualResults = doTest(Factory.newDocument(""), japeFilePath, annoCreatorEmpty, null);
0055     assertEquals("There must be no transduced annotations."0, actualResults.size());
0056   }
0057 
0058   /**
0059    * GATE Tao:8.1.1
0060    
0061    @throws Exception
0062    */
0063   public void test811MatchText() throws Exception {
0064     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.1.jape";
0065     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.1.txt";
0066 
0067     String[] expectedResults = {"SimpleText""ComplexText""ComplexText",
0068         "ComplexText""ComplexText"};
0069     int[] expectedStartOffsets = {14112643};
0070     int[] expectedEndOffsets = {311153247};
0071 
0072     AnnotationCreator annocreator = new BaseAnnotationCreator() {
0073       public AnnotationSet createAnnots(Document doc)
0074               throws InvalidOffsetException {
0075         FeatureMap feat = Factory.newFeatureMap();
0076         feat.put("string""of");
0077         add(13"Token", feat);
0078 
0079         feat = Factory.newFeatureMap();
0080         feat.put("string""http");
0081         add(48"Token", feat);
0082         feat = Factory.newFeatureMap();
0083         feat.put("string"":");
0084         add(89"Token", feat);
0085         feat = Factory.newFeatureMap();
0086         feat.put("string""/");
0087         add(910"Token", feat);
0088         feat = Factory.newFeatureMap();
0089         feat.put("string""/");
0090         add(1011"Token", feat);
0091         feat = Factory.newFeatureMap();
0092         feat.put("string""www");
0093         add(1114"Token", feat);
0094         feat = Factory.newFeatureMap();
0095         feat.put("string"".");
0096         add(1415"Token", feat);
0097 
0098         feat = Factory.newFeatureMap();
0099         feat.put("string""ftp");
0100         add(2629"Token", feat);
0101         feat = Factory.newFeatureMap();
0102         feat.put("string"":");
0103         add(2930"Token", feat);
0104         feat = Factory.newFeatureMap();
0105         feat.put("string""/");
0106         add(3031"Token", feat);
0107         feat = Factory.newFeatureMap();
0108         feat.put("string""/");
0109         add(3132"Token", feat);
0110         feat = Factory.newFeatureMap();
0111 
0112         feat = Factory.newFeatureMap();
0113         feat.put("string""www");
0114         add(3742"Token", feat);
0115         feat = Factory.newFeatureMap();
0116         feat.put("string"".");
0117         add(4243"Token", feat);
0118         return as;
0119       }
0120     };
0121 
0122     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annocreator);
0123   }
0124 
0125   /**
0126    * GATE Tao:8.1.1
0127    
0128    * Trying to match string features on document with no annotations
0129    
0130    @throws Exception
0131    */
0132   public void test811MatchStringInEmptyAnnotSet() throws Exception {
0133     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.1.jape";
0134     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.1.txt";
0135     Set<Annotation> actualResults = doTest(docFilePath, japeFilePath, annoCreatorEmpty);
0136     assertEquals("There must be no transduced annotations."0, actualResults.size());
0137   }
0138 
0139   /**
0140    * GATE Tao: 8.1.2
0141    
0142    @throws Exception
0143    */
0144   public void test812MatchAnnot() throws Exception {
0145     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.2.jape";
0146     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.2.txt";
0147 
0148     String[] expectedResults = {"SimpleAnnotation""SimpleAnnotation"};
0149     int[] expectedStartOffsets = {1101};
0150     int[] expectedEndOffsets = {53137};
0151 
0152     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator81LocOrgDateJob);
0153   }
0154 
0155   /**
0156    * GATE Tao: 8.1.2
0157    
0158    * Trying to match annotations on document with no annotations
0159    
0160    @throws Exception
0161    */
0162   public void test812MatchNegativeAnnotationsInEmptyAnnotSet() throws Exception {
0163     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.2-Negative.jape";
0164     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.2.txt";
0165     Set<Annotation> actualResults = doTest(docFilePath, japeFilePath, annoCreatorEmpty);
0166     assertEquals("There must be no transduced annotations."0, actualResults.size());
0167   }
0168 
0169   /**
0170    * GATE Tao: 8.1.2
0171    
0172    * Matching negation on annotation (e.g {!Lookup}) on a document with annotations
0173    
0174    @throws Exception
0175    */
0176   public void test812MatchNegativeAnnotations() throws Exception {
0177     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.2.jape";
0178     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.2.txt";
0179 
0180     String[] expectedResults = {"NegativeAnnotation""NegativeAnnotation""NegativeAnnotation"};
0181     int[] expectedStartOffsets = {1669111};
0182     int[] expectedEndOffsets = {53100137};
0183 
0184     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator81LocOrgDateJob);
0185   }
0186 
0187   /**
0188    * GATE Tao: 8.1.3
0189    
0190    * LHS Operators:  contains
0191    @throws Exception 
0192    
0193    
0194    */
0195   public void test813OpContains() throws Exception {
0196     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-LHSOP_contains.jape";
0197     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.2.txt";
0198 
0199     String[] expectedResults = {"OpContains""OpContains""OpContains"};
0200     int[] expectedStartOffsets = {154101};
0201     int[] expectedEndOffsets = {1568110};
0202 
0203     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator81LocOrgDateJob);
0204   }
0205   
0206 
0207   
0208   /**
0209    * GATE Tao: 8.1.3
0210    
0211    * LHS Operators:  within
0212    @throws Exception 
0213    
0214    */
0215   public void test813OpWithin() throws Exception {
0216     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-LHSOP_within.jape";
0217     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.2.txt";
0218 
0219     String[] expectedResults = {"OpWithin""OpWithin""OpWithin""OpWithin""OpWithin""OpWithin"};
0220     int[] expectedStartOffsets = {175460101108};
0221     int[] expectedEndOffsets = {6155968107110};
0222 
0223     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator81LocOrgDateJob);
0224   }
0225   
0226   /**
0227    * GATE Tao: 8.1.3
0228    
0229    * LHS Operators:  contains & within in document with no annotations
0230    @throws Exception 
0231    
0232    */
0233   public void test813OpContainWithinNoMatch() throws Exception {
0234     final String japeContainsFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-LHSOP_contains.jape";
0235     final String japeWithinFilePath =  "/jape/test/japefiles/Req-GATETao-8.1.3-LHSOP_within.jape";
0236     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.2.txt";
0237 
0238     Set<Annotation> actualResults = doTest(docFilePath, japeWithinFilePath, annoCreatorEmpty);
0239     assertEquals("There must be no transduced annotations."0, actualResults.size());
0240     
0241     actualResults = doTest(docFilePath, japeContainsFilePath, annoCreatorEmpty);
0242     assertEquals("There must be no transduced annotations."0, actualResults.size());
0243   }
0244   
0245   /**
0246    * Gate Tao: 8.1.3
0247    
0248    * Operator: ==
0249    * Case: Special characters in the rule and text (quote here)
0250    
0251    @throws Exception
0252    */
0253   public void test813OpEqualsStringSpecialChars() throws Exception {
0254     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-equals-string-wquot.jape";
0255     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0256     
0257     String[] expectedResults = {"OpEquals"};
0258     int[] expectedStartOffsets = {6};
0259     int[] expectedEndOffsets = {13};
0260 
0261     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0262   }
0263   
0264   /**
0265    * Gate Tao: 8.1.3
0266    
0267    * Operator: ==
0268    * Case: Emty String feature
0269    
0270    @throws Exception
0271    */
0272   public void test813OpEqualsStringEmptyFeature() throws Exception {
0273     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-equals-string-ef.jape";
0274     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0275     
0276     String[] expectedResults = {"OpEquals""OpEquals"};
0277     int[] expectedStartOffsets = {135};
0278     int[] expectedEndOffsets = {543};
0279     
0280     AnnotationCreator operatorsAnnoCreator = new BaseAnnotationCreator() {
0281       public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
0282         FeatureMap feat = Factory.newFeatureMap();
0283         feat.put("string""");
0284         add(15"Token", feat);
0285         
0286         feat = Factory.newFeatureMap();
0287         feat.put("string""qu\"oted");
0288         add(613"Token", feat);
0289         
0290         feat = Factory.newFeatureMap();
0291         feat.put("int"101l);
0292         add(1417"Token", feat);
0293         
0294         feat = Factory.newFeatureMap();
0295         feat.put("int", -10);
0296         add(1821"Token", feat);
0297         
0298         feat = Factory.newFeatureMap();
0299         feat.put("double"3.14f);
0300         add(2226"Token", feat);
0301         
0302         feat = Factory.newFeatureMap();
0303         feat.put("double", -273.15);
0304         add(2734"Token", feat);
0305         
0306         feat = Factory.newFeatureMap();
0307         feat.put("string""");
0308         add(3543"Token", feat);
0309         return as;
0310       }
0311     };
0312 
0313     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, operatorsAnnoCreator);
0314   }
0315   
0316   /**
0317    * GATE Tao: 8.1.3
0318    
0319    * Operator: ==
0320    * Case: Natural number
0321    
0322    @throws Exception
0323    */
0324   public void test813OpEqualsIntegerNatural() throws Exception {
0325     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-equals-int-natural.jape";
0326     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0327     
0328     String[] expectedResults = {"OpEquals"};
0329     int[] expectedStartOffsets = {14};
0330     int[] expectedEndOffsets = {17};
0331   
0332     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0333   }
0334   
0335   /**
0336    * GATE Tao: 8.1.3
0337    
0338    * Operator: ==
0339    * Case: Negative integer
0340    
0341    @throws Exception
0342    */
0343   public void test813OpEqualsIntegerNegative() throws Exception {
0344     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-equals-int-negative.jape";
0345     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0346     
0347     String[] expectedResults = {"OpEquals"};
0348     int[] expectedStartOffsets = {18};
0349     int[] expectedEndOffsets = {21};
0350   
0351     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0352   }
0353   
0354   /**
0355    * GATE Tao: 8.1.3
0356    
0357    * Operator: ==
0358    * Case: Positive real number
0359    
0360    @throws Exception
0361    */
0362   public void test813OpEqualsDoublePositive() throws Exception {
0363     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-equals-double-positive.jape";
0364     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0365     
0366     String[] expectedResults = {"OpEquals"};
0367     int[] expectedStartOffsets = {22};
0368     int[] expectedEndOffsets = {26};
0369   
0370     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0371   }
0372   
0373   /**
0374    * GATE Tao: 8.1.3
0375    
0376    * Operator: ==
0377    * Case: Negative real number
0378    
0379    @throws Exception
0380    */
0381   public void test813OpEqualsDoubleNegative() throws Exception {
0382     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-equals-double-negative.jape";
0383     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0384     
0385     String[] expectedResults = {"OpEquals"};
0386     int[] expectedStartOffsets = {27};
0387     int[] expectedEndOffsets = {34};
0388   
0389     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0390   }
0391   
0392   
0393   /**
0394    * GATE Tao: 8.1.3
0395    
0396    * Operator: >
0397    * Case: String
0398    
0399    @throws Exception
0400    */
0401   public void test813OpGreaterThanString() throws Exception {
0402     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-gt-string.jape";
0403     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0404     
0405     String[] expectedResults = {"OpGreaterThan""OpGreaterThan""OpGreaterThan"};
0406     int[] expectedStartOffsets = {1,35};
0407     int[] expectedEndOffsets = {51343};
0408   
0409     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0410   }
0411   
0412   /**
0413    * GATE Tao: 8.1.3
0414    
0415    * Operator: >
0416    * Case: Natural Number
0417    
0418    @throws Exception
0419    */
0420   public void test813OpGreaterThanNaturalNumber() throws Exception {
0421     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-gt-int-positive.jape";
0422     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0423     
0424     String[] expectedResults = {"OpGreaterThan""OpGreaterThan"};
0425     int[] expectedStartOffsets = {1422};
0426     int[] expectedEndOffsets = {1726};
0427   
0428     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0429   }
0430   
0431   
0432   /**
0433    * GATE Tao: 8.1.3
0434    
0435    * Operator: >
0436    * Case: Negative Integer
0437    
0438    @throws Exception
0439    */
0440   public void test813OpGreaterThanNegativeInteger() throws Exception {
0441     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-gt-int-negative.jape";
0442     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0443     
0444     String[] expectedResults = {"OpGreaterThan""OpGreaterThan""OpGreaterThan""OpGreaterThan"};
0445     int[] expectedStartOffsets = {14182227};
0446     int[] expectedEndOffsets = {17212634};
0447   
0448     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0449   }
0450   
0451   /**
0452    * GATE Tao: 8.1.3
0453    
0454    * Operator: >
0455    * Case: Positive Real Number
0456    
0457    @throws Exception
0458    */
0459   public void test813OpGreaterThanPositiveDouble() throws Exception {
0460     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-gt-double-positive.jape";
0461     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0462     
0463     String[] expectedResults = {"OpGreaterThan""OpGreaterThan"};
0464     int[] expectedStartOffsets = {1422};
0465     int[] expectedEndOffsets = {1726};
0466   
0467     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0468   }
0469   
0470   /**
0471    * GATE Tao: 8.1.3
0472    
0473    * Operator: >
0474    * Case: Negative Real Number
0475    
0476    @throws Exception
0477    */
0478   public void test813OpGreaterThanNegativeDouble() throws Exception {
0479     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-gt-double-negative.jape";
0480     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0481     
0482     String[] expectedResults = {"OpGreaterThan""OpGreaterThan""OpGreaterThan""OpGreaterThan"};
0483     int[] expectedStartOffsets = {14182227};
0484     int[] expectedEndOffsets = {17212634};
0485   
0486     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0487   }
0488   
0489   /**
0490    * GATE Tao: 8.1.3
0491    
0492    * Operator: >=
0493    * Case: String
0494    
0495    @throws Exception
0496    */
0497   public void test813OpGreaterEqualsString() throws Exception {
0498     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-ge-string.jape";
0499     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0500     
0501     String[] expectedResults = {"OpGreaterEquals"};
0502     int[] expectedStartOffsets = {1};
0503     int[] expectedEndOffsets = {5};
0504   
0505     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0506   }
0507   
0508   /**
0509    * GATE Tao: 8.1.3
0510    
0511    * Operator: >=
0512    * Case: Positive Integer
0513    
0514    @throws Exception
0515    */
0516   public void test813OpGreaterЕqualsPositiveInteger() throws Exception {
0517     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-ge-int-positive.jape";
0518     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0519     
0520     String[] expectedResults = {"OpGreaterEquals"};
0521     int[] expectedStartOffsets = {14};
0522     int[] expectedEndOffsets = {17};
0523   
0524     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0525   }
0526   
0527   /**
0528    * GATE Tao: 8.1.3
0529    
0530    * Operator: >=
0531    * Case: Negative Integer
0532    
0533    @throws Exception
0534    */
0535   public void test813OpGreaterEqualsNegativeInteger() throws Exception {
0536     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-ge-int-negative.jape";
0537     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0538     
0539     String[] expectedResults = {"OpGreaterEquals""OpGreaterEquals""OpGreaterEquals"};
0540     int[] expectedStartOffsets = {141822};
0541     int[] expectedEndOffsets = {172126};
0542   
0543     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0544   }
0545  
0546   /**
0547    * GATE Tao: 8.1.3
0548    
0549    * Operator: >=
0550    * Case: Positive Real Number
0551    
0552    @throws Exception
0553    */
0554   public void test813OpGreaterEqualsPositiveDouble() throws Exception {
0555     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-ge-double-positive.jape";
0556     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0557     
0558     String[] expectedResults = {"OpGreaterEquals""OpGreaterEquals"};
0559     int[] expectedStartOffsets = {1422};
0560     int[] expectedEndOffsets = {1726};
0561   
0562     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0563   }
0564   
0565   /**
0566    * GATE Tao: 8.1.3
0567    
0568    * Operator: >=
0569    * Case: Negative Real Number
0570    
0571    @throws Exception
0572    */
0573   public void test813OpGreaterEqualsNegativeDouble() throws Exception {
0574     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.3-op-ge-double-negative.jape";
0575     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.3.txt";
0576     
0577     String[] expectedResults = {"OpGreaterEquals""OpGreaterEquals""OpGreaterEquals""OpGreaterEquals"};
0578     int[] expectedStartOffsets = {14182227};
0579     int[] expectedEndOffsets = {17212634};
0580   
0581     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator813Operators);
0582   }
0583   
0584   /**
0585    *  GATE Tao: 8.1.4
0586    
0587    * Meta-Property: LHS length
0588    
0589    @throws Exception
0590    */
0591   public void test814MetaLeftLength() throws Exception {
0592     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.4-meta-length.jape";
0593     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.4.txt";
0594     
0595     String[] expectedResults = {"MetaLength"};
0596     int[] expectedStartOffsets = {1};
0597     int[] expectedEndOffsets = {61};
0598     
0599     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator814MetaProps);
0600     }
0601   
0602   /**
0603    *  GATE Tao: 8.1.4
0604    
0605    * Meta-Property: LHS string
0606    
0607    @throws Exception
0608    */
0609   public void test814MetaLeftString() throws Exception {
0610     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.4-meta-string.jape";
0611     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.4.txt";
0612     
0613     String[] expectedResults = {"MetaString"};
0614     int[] expectedStartOffsets = {1};
0615     int[] expectedEndOffsets = {61};
0616     
0617     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator814MetaProps);
0618   }
0619   
0620   /**
0621    *  GATE Tao: 8.1.4
0622    
0623    * Meta-Property: LHS cleanString
0624    
0625    @throws Exception
0626    */
0627   public void test814MetaLeftCleanString() throws Exception {
0628     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.4-meta-cleanString.jape";
0629     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.4.txt";
0630     
0631     String[] expectedResults = {"MetaCleanString"};
0632     int[] expectedStartOffsets = {1};
0633     int[] expectedEndOffsets = {61};
0634     
0635     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator814MetaProps);
0636   }
0637   
0638   /**
0639    *  GATE Tao: 8.1.4
0640    
0641    * Meta-Property: RHS string
0642    
0643    @throws Exception
0644    */
0645   public void test814MetaRightString() throws Exception {
0646     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.4-meta-rhs-string.jape";
0647     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.4.txt";
0648     
0649     String[] expectedResults = {"MetaRightString"};
0650     int[] expectedStartOffsets = {1};
0651     int[] expectedEndOffsets = {61};
0652 
0653     Set<Annotation> actualResults = doTest(docFilePath, japeFilePath, annoCreator814MetaProps);
0654     
0655     compareResults(expectedResults, actualResults);
0656     compareStartOffsets(actualResults, expectedStartOffsets);
0657     compareEndOffsets(actualResults, expectedEndOffsets);
0658     
0659     FeatureMap feats = actualResults.iterator().next().getFeatures();
0660     Object oValue = feats.get("value");
0661     assertNotNull("Annotation features must contain \"value\" feature", oValue);
0662     assertEquals("RHS value must be equals to matched text""     and when    the   lamb opened  the     seventh     seal"(String)oValue);
0663   
0664   }
0665   
0666   /**
0667    * GATE Tao: 8.1.5
0668    
0669    * Multiple Patterns/Actions - Sequential
0670    
0671    @throws Exception
0672    */
0673   public void test815MultiPatternActionsSequential() throws Exception{
0674     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.5-multipat-seq.jape";
0675     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.5.txt";
0676     
0677     String[] expectedResults = {"PersonJobTitle1""PersonJobTitle2"};
0678     int[] expectedStartOffsets = {613};
0679     int[] expectedEndOffsets = {1221};
0680     
0681     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator815MultipleActions);
0682   
0683   }
0684   
0685   /**
0686    * GATE Tao: 8.1.5
0687    
0688    * Multiple Patterns/Actions - Nested
0689    
0690    @throws Exception
0691    */
0692   public void test815MultiPatternActionsNested() throws Exception{
0693     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.5-multipat-nest.jape";
0694     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.5.txt";
0695     
0696     String[] expectedResults = {"PersonJobTitle1""PersonJobTitle2"};
0697     int[] expectedStartOffsets = {3636};
0698     int[] expectedEndOffsets = {5059};
0699     
0700     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator815MultipleActions);
0701   }
0702   
0703   
0704   /**
0705    * GATE Tao: 8.1.6
0706    
0707    * LHS Macros
0708    
0709    @throws Exception
0710    */
0711   public void test816Macro() throws Exception{
0712     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.6-macro.jape";
0713     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.6.txt";
0714     
0715     String[] expectedResults = {"MoneyCurrencyUnit""MoneyCurrencyUnit"};
0716     int[] expectedStartOffsets = {3149};
0717     int[] expectedEndOffsets = {4457};
0718     
0719     AnnotationCreator annoCreator816Macros = new BaseAnnotationCreator() {
0720       public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
0721         final String token = "Token";
0722         FeatureMap feats = Factory.newFeatureMap();
0723         feats.put("kind""number");
0724         add(3132, token, feats);
0725         add(3336, token, feats);
0726         add(4953, token, feats);
0727         
0728         feats = Factory.newFeatureMap();
0729         feats.put("string"",");
0730         add(32,33, token, feats);
0731         
0732         feats = Factory.newFeatureMap();
0733         feats.put("string""K");
0734         add(3636, token, feats);
0735 
0736         feats = Factory.newFeatureMap();
0737         feats.put("majorType""currency_unit");
0738         add(4144"Lookup", feats);
0739         
0740         feats = Factory.newFeatureMap();
0741         feats.put("majorType""currency_unit");
0742         add(5457"Lookup", feats);
0743         return as;
0744       }
0745     };
0746     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator816Macros);
0747   }
0748   
0749   /**
0750    * GATE Tao: 8.1.7
0751    
0752    * Contexts
0753    
0754    @throws Exception
0755    */
0756   public void test817ContextForeAndAft() throws Exception{
0757     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.7-ctx-foreaft.jape";
0758     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.7.txt";
0759     
0760     String[] expectedResults = {"Emailaddress1"};
0761     int[] expectedStartOffsets = {9};
0762     int[] expectedEndOffsets = {25};
0763     
0764     
0765     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator817Contexts);
0766   }
0767   
0768   /**
0769    * GATE Tao: 8.1.8
0770    
0771    * Contexts
0772    
0773    @throws Exception
0774    */
0775   public void test818ContextBeginsAt() throws Exception{
0776     final String japeFilePath = "/jape/test/japefiles/Req-GATETao-8.1.7-ctx-begins.jape";
0777     final String docFilePath = "/jape/test/docfiles/Req-GATETao-8.1.7.txt";
0778     
0779     String[] expectedResults = {"SurnameStartingWithDe"};
0780     int[] expectedStartOffsets = {58};
0781     int[] expectedEndOffsets = {66};
0782     
0783     doCommonTest(japeFilePath, docFilePath, expectedResults, expectedStartOffsets, expectedEndOffsets, annoCreator817Contexts);
0784   }
0785   
0786   
0787   public void testGoodOperators() throws Exception {
0788     String japeFile = "/jape/operators/operator_tests.jape";
0789     String[] expectedResults = {"AndEqual""RegExMatch",
0790         "NotEqualandGreaterEqual""NotEqual""EqualAndNotEqualRegEx",
0791         "EqualAndNotExistance""OntoTest""OntoTest2"};
0792 
0793     Set<Annotation> actualResults = doTest(DEFAULT_DATA_FILE, japeFile,
0794             basicAnnotCreator, "http://gate.ac.uk/tests/demo.owl");
0795     Out.println(actualResults);
0796     compareResults(expectedResults, actualResults);
0797   }
0798 
0799   public void testBadCompare() throws Exception {
0800     String japeFile = "/jape/operators/bad_operator_tests.jape";
0801 
0802     Set<Annotation> orderedResults = doTest(DEFAULT_DATA_FILE, japeFile,
0803             basicAnnotCreator);
0804     assertTrue("No results should be found", orderedResults.isEmpty());
0805   }
0806 
0807   public void testBadPattern() throws Exception {
0808     final String JAPE_PREFIX = "Phase: first\n Options: control = appelt\nRule: RuleOne\n";
0809     String japeString = JAPE_PREFIX + "({A.f1=~\"[a.\"}):abc" "-->{}";
0810 
0811     try {
0812       parseJapeString(japeString);
0813       assertTrue("Should have thrown exception for bad grammer"false);
0814     }
0815     catch(ParseException e) {
0816       Out.println(e.getMessage());
0817     }
0818 
0819     japeString = JAPE_PREFIX + "({A.f1=~[a.}):abc" "-->{}";
0820     try {
0821       parseJapeString(japeString);
0822       assertTrue("Should have thrown exception for bad grammer"false);
0823     }
0824     catch(ParseException e) {
0825       Out.println(e.getMessage());
0826       // insert test of error message if really want
0827     }
0828   }
0829 
0830   public void testMetaPropertyAccessors() throws Exception {
0831     String data = "foo bar blah word4    word5  ";
0832     String japeFile = "/jape/operators/meta_property_tests.jape";
0833     String[] expectedResults = {"LengthAccessorEqual""StringAccessorEqual",
0834         "CleanStringAccessorEqual"};
0835 
0836     AnnotationCreator ac = new BaseAnnotationCreator() {
0837       public AnnotationSet createAnnots(Document doc)
0838               throws InvalidOffsetException {
0839         FeatureMap feat = Factory.newFeatureMap();
0840         feat.put("f1""aval");
0841         feat.put("f2""2");
0842         feat.put("f3"3);
0843         add(47"A", feat);
0844 
0845         add(812"A");
0846         add(1228"B");
0847         return as;
0848       }
0849     };
0850 
0851     Set<Annotation> actualResults = doTest(Factory.newDocument(data), japeFile,
0852             ac, null);
0853     Out.println(actualResults);
0854     compareResults(expectedResults, actualResults);
0855   }
0856 
0857   public void testCustomPredicates() throws Exception {
0858     String japeFile = "/jape/operators/custom_predicates_tests.jape";
0859     String[] expectedResults = {"Contains""IsContained""Contains",
0860         "IsContained"};
0861 
0862     AnnotationCreator ac = new BaseAnnotationCreator() {
0863       public AnnotationSet createAnnots(Document doc)
0864               throws InvalidOffsetException {
0865         add(47"A");
0866 
0867         // this feature map isn't necessary. Just including it
0868         // to make sure it doesn't interfere with anything.
0869         FeatureMap feat = Factory.newFeatureMap();
0870         feat.put("f2""bar");
0871         add(56"B", feat);
0872 
0873         add(1228"F");
0874         add(1420"E");
0875 
0876         // test exact length matches
0877         add(3035"A");
0878         add(3035"B");
0879 
0880         add(4045"F");
0881         add(4045"E");
0882 
0883         // these shouldn't match
0884         add(3637"A");
0885         add(3638"B");
0886         add(3738"B");
0887 
0888         add(4045"F");
0889         add(4046"E");
0890         add(4146"E");
0891 
0892         return as;
0893       }
0894     };
0895 
0896     Set<Annotation> actualResults = doTest(DEFAULT_DATA_FILE, japeFile, ac);
0897     Out.println(actualResults);
0898     compareResults(expectedResults, actualResults);
0899   }
0900 
0901   public void testCustomPredicatesWithConstraints() throws Exception {
0902     String japeFile = "/jape/operators/custom_predicates_tests.jape";
0903     String[] expectedResults = {"ContainsWithConstraints",
0904         "ContainsWithMetaProperty"};
0905 
0906     AnnotationCreator ac = new BaseAnnotationCreator() {
0907       public AnnotationSet createAnnots(Document doc)
0908               throws InvalidOffsetException {
0909         FeatureMap cFeat = Factory.newFeatureMap();
0910         cFeat.put("f1""foo");
0911         add(47"C", cFeat);
0912         add(48"C", Factory.newFeatureMap());
0913 
0914         FeatureMap bFeat = Factory.newFeatureMap();
0915         bFeat.put("f2""bar");
0916         add(56"B", bFeat);
0917 
0918         // this combo won't work because B doesn't have the feature and
0919         // isn't long enough
0920         add(810"C", cFeat);
0921         add(89"B");
0922 
0923         add(1113"C");
0924         // a combo that should work
0925         add(1216"C", cFeat);
0926         add(1215"C");
0927         add(1216"B");
0928 
0929         // here's one with no B at all
0930         add(1720"C", cFeat);
0931 
0932         return as;
0933       }
0934     };
0935 
0936     Set<Annotation> actualResults = doTest(DEFAULT_DATA_FILE, japeFile, ac);
0937     Out.println(actualResults);
0938     compareResults(expectedResults, actualResults);
0939   }
0940 
0941   public void testRanges() throws Exception {
0942     String japeFile = "/jape/operators/range_tests.jape";
0943     String[] expectedResults = {"OneToTwoB""ThreeA""OneToTwoB",
0944         "ZeroToThreeC""ThreeToFourB""ThreeToFourB""ZeroToThreeC",
0945         "ZeroToThreeC"};
0946 
0947     AnnotationCreator ac = new BaseAnnotationCreator() {
0948       public AnnotationSet createAnnots(Document doc)
0949               throws InvalidOffsetException {
0950 
0951         // OneToTwoB check
0952         addInc("F");
0953         addInc("B");
0954         addInc("G");
0955 
0956         // ThreeA check
0957         addInc("A");
0958         addInc("A");
0959         addInc("A");
0960 
0961         // should not trigger OneToTwoB
0962         addInc("F");
0963         addInc("G");
0964 
0965         // ThreeA check - should not match
0966         addInc("A");
0967         addInc("A");
0968 
0969         // OneToTwoB - trigger it once for two different variants
0970         addInc("F");
0971         addInc("B");
0972         addInc("G");
0973         addInc("F");
0974         addInc("B");
0975         addInc("B");
0976         addInc("G");
0977 
0978         // ZeroToThreeC check - no Cs
0979         addInc("D");
0980         addInc("E");
0981 
0982         // ThreeToFourB
0983         addInc("F");
0984         addInc("B");
0985         addInc("B");
0986         // addInc("B");
0987         addInc("G");
0988         addInc("F");
0989         addInc("B");
0990         addInc("B");
0991         addInc("B");
0992         addInc("B");
0993         addInc("G");
0994 
0995         // ZeroToThreeC check - 1 C
0996         addInc("D");
0997         addInc("C");
0998         // addInc("E");
0999 
1000         // ZeroToThreeC check - 3 C
1001         addInc("D");
1002         addInc("C");
1003         // addInc("C");
1004         addInc("C");
1005         addInc("E");
1006 
1007         // ZeroToThreeC check - 4 C = no match addInc("D"); addInc("C");
1008         addInc("C");
1009         addInc("C");
1010         addInc("C");
1011         addInc("E");
1012 
1013         return as;
1014       }
1015     };
1016 
1017     Set<Annotation> actualResults = doTest(DEFAULT_DATA_FILE, japeFile, ac);
1018     Out.println(actualResults);
1019     compareResults(expectedResults, actualResults);
1020   }
1021 
1022   public void testKleeneOperators() throws Exception {
1023     String japeFile = "/jape/operators/kleene_tests.jape";
1024     String[] expectedResults = {"OptionalB""PlusA""OptionalB""PlusA",
1025         "StarC""StarC""StarC"};
1026 
1027     AnnotationCreator ac = new BaseAnnotationCreator() {
1028       public AnnotationSet createAnnots(Document doc)
1029               throws InvalidOffsetException // OptionalB check
1030         // addInc("C");
1031         addInc("B");
1032         addInc("C");
1033 
1034         // PlusA check
1035         addInc("A");
1036         addInc("A");
1037         addInc("A");
1038 
1039         // OptionalB check
1040         addInc("C");
1041         addInc("C");
1042         // PlusA
1043         // addInc("A");
1044         addInc("A");
1045 
1046         // no match
1047         addInc("B");
1048 
1049         // StarC
1050         addInc("D");
1051         addInc("E");
1052 
1053         // StarC
1054         addInc("D");
1055         addInc("C");
1056         addInc("E");
1057 
1058         // StarC
1059         addInc("D");
1060         addInc("C");
1061         addInc("C");
1062         addInc("C");
1063         addInc("E");
1064 
1065         return as;
1066       }
1067     };
1068 
1069     Set<Annotation> actualResults = doTest(DEFAULT_DATA_FILE, japeFile, ac);
1070     Out.println(actualResults);
1071     compareResults(expectedResults, actualResults);
1072   }
1073 
1074   /* Utility features */
1075 public void doCommonTest(String japeFilePath, String docFilePath, 
1076         String[] expectedResults, int[] expectedStartOffsets, int[] expectedEndOffsets, 
1077         AnnotationCreator annocreatorthrows Exception {
1078    
1079   Set<Annotation> actualResults = doTest(docFilePath, japeFilePath, annocreator);
1080   
1081   compareResults(expectedResults, actualResults);
1082   compareStartOffsets(actualResults, expectedStartOffsets);
1083   compareEndOffsets(actualResults, expectedEndOffsets);
1084 }
1085   
1086 private final   AnnotationCreator annoCreatorEmpty = new BaseAnnotationCreator() {
1087   public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
1088     return as;
1089   }
1090 };
1091 
1092 private final AnnotationCreator annoCreator81LocOrgDateJob = new BaseAnnotationCreator() {
1093   public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
1094     /* line 1 */
1095     add(16"Location");
1096     add(115"Location");
1097     add(715"Location");
1098     add(1624"Organization");
1099     FeatureMap feat = Factory.newFeatureMap();
1100     feat.put("month""September");
1101     add(2535"Date", feat);
1102     add(3653"JobTitle");
1103     
1104     /* line 2 */
1105     add(5459"Location");
1106     add(5468"Location");
1107     add(6068"Location");
1108     add(6977"Organization");
1109     feat = Factory.newFeatureMap();
1110     feat.put("month""November");
1111     add(7888"Date", feat);
1112     add(89100"JobTitle");
1113     
1114     /* line 3 */
1115     add(101107"Location");
1116     add(101110"Location");
1117     add(108110"Location");
1118     add(111115"Organization");
1119     
1120     feat = Factory.newFeatureMap();
1121     feat.put("month""October");
1122     add(116126"Date", feat);
1123     
1124     add(127137"JobTitle");
1125     
1126     return as;
1127   }
1128 };
1129   
1130 private final AnnotationCreator annoCreator813Operators = new BaseAnnotationCreator() {
1131   public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
1132     FeatureMap feat = Factory.newFeatureMap();
1133     feat.put("string""room");
1134     add(15"Token", feat);
1135     
1136     feat = Factory.newFeatureMap();
1137     feat.put("string""qu\"oted");
1138     add(613"Token", feat);
1139     
1140     feat = Factory.newFeatureMap();
1141     feat.put("int"101l);
1142     add(1417"Token", feat);
1143     
1144     feat = Factory.newFeatureMap();
1145     feat.put("int", -10);
1146     add(1821"Token", feat);
1147     
1148     feat = Factory.newFeatureMap();
1149     feat.put("double"3.14f);
1150     add(2226"Token", feat);
1151     
1152     feat = Factory.newFeatureMap();
1153     feat.put("double", -273.15);
1154     add(2734"Token", feat);
1155     
1156     feat = Factory.newFeatureMap();
1157     feat.put("string""qu\\\"oted");
1158     add(3543"Token", feat);
1159     return as;
1160   }
1161 };
1162 
1163 private final  AnnotationCreator annoCreator814MetaProps = new BaseAnnotationCreator() {
1164   public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
1165     add(161"Span");
1166     return as;
1167   }
1168 };
1169 
1170 private final AnnotationCreator annoCreator815MultipleActions = new BaseAnnotationCreator() {
1171   public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
1172     final String tp = "TempPerson";
1173     add(15, tp);
1174     
1175     FeatureMap feats = Factory.newFeatureMap();
1176     feats.put("majorType""jobtitle");
1177     add(6,12"Lookup", feats);
1178     add(1321, tp);
1179     
1180     add(3650"Lookup", feats);
1181     add(3659, tp);
1182     
1183     return as;
1184   }
1185 };
1186 
1187 private final AnnotationCreator annoCreator817Contexts = new BaseAnnotationCreator() {
1188   public AnnotationSet createAnnots(Document docthrows InvalidOffsetException {
1189     final String tok = "Token";
1190     final String str = "string";
1191     
1192     FeatureMap feats = Factory.newFeatureMap();
1193     feats.put("type""elmail");
1194     add(925"Annotation", feats);
1195     add(3044"Annotation", feats);
1196    
1197     feats = Factory.newFeatureMap();
1198     feats.put(str, "<");
1199     add(8,9, tok, feats);
1200     
1201     feats = Factory.newFeatureMap();
1202     feats.put(str, ">");
1203     add(2526, tok, feats);
1204 
1205     feats = Factory.newFeatureMap();
1206     feats.put(str, "de");
1207     add(5860, tok, feats);
1208     
1209     feats = Factory.newFeatureMap();
1210     feats.put("majorType""name");
1211     feats.put("minorType""surname");
1212     add(5866"Lookup", feats);
1213 
1214     return as;
1215   }
1216 };
1217 
1218   /**
1219    * Visually, this creates an annot set like this:
1220    * 0-------------1--------------2 12345678901234567890 _AA
1221    * (f1,"atext"), (f2,"2"), (f3,3) _B
1222    * (f1,"btext),  (f2,"2"),  (f4,"btext4") ___BB
1223    * (f1,"btext),  (f2,"2"),  (f4,"btext4") ______B (f1,"cctext"),
1224    * (f2,"2"), (f3,3l), (f4,"ctext4") ______CC (f1,"cctext"), (f2,"2"),
1225    * (f3,3l), (f4,"ctext4") ________CC (f1,"cctext"), (f2,"1"),
1226    * (f4,"ctext4") _____________DD (f1,"dtext"), (f3,3l)
1227    * _______________DD (f2,2l) _________________DD (ontology,
1228    * "http://gate.ac.uk/tests/demo.owl"), (class, "Businessman")
1229    * ____________________D (ontology,
1230    * "http://gate.ac.uk/tests/demo.owl"), (class, "Country")
1231    * 0-------------1--------------2 12345678901234567890
1232    */
1233   protected AnnotationCreator basicAnnotCreator = new BaseAnnotationCreator() {
1234     public AnnotationSet createAnnots(Document doc)
1235             throws InvalidOffsetException {
1236       FeatureMap feat = Factory.newFeatureMap();
1237       feat.put("f1""atext");
1238       feat.put("f2""2");
1239       feat.put("f3"3);
1240       add(24"A", feat);
1241 
1242       feat = Factory.newFeatureMap();
1243       feat.put("f1""btext");
1244       feat.put("f2""2");
1245       feat.put("f4""btext4");
1246       add(23"B", feat);
1247       add(46"B", feat);
1248 
1249       feat = Factory.newFeatureMap();
1250       feat.put("f1""cctext");
1251       feat.put("f2""2");
1252       feat.put("f3"3l);
1253       feat.put("f4""ctext4");
1254       add(67"B", feat);
1255       add(68"C", feat);
1256 
1257       feat = Factory.newFeatureMap();
1258       feat.put("f1""cctext");
1259       feat.put("f2""1");
1260       feat.put("f4""ctext4");
1261       add(810"C", feat);
1262 
1263       feat = Factory.newFeatureMap();
1264       feat.put("f1""dtext");
1265       feat.put("f3"3l);
1266       add(1214"D", feat);
1267 
1268       feat = Factory.newFeatureMap();
1269       feat.put("f2"2l);
1270       add(1416"D", feat);
1271 
1272       feat = Factory.newFeatureMap();
1273       feat.put("ontology""http://gate.ac.uk/tests/demo.owl");
1274       feat.put("class""Businessman");
1275       add(1618"D", feat);
1276 
1277       feat = Factory.newFeatureMap();
1278       feat.put("ontology""http://gate.ac.uk/tests/demo.owl");
1279       feat.put("class""Country");
1280       add(1819"D", feat);
1281       return as;
1282     }
1283   };
1284 
1285   /**
1286    * Fast routine for parsing a small string of JAPE rules.
1287    
1288    @param japeRules
1289    @throws ParseException
1290    */
1291   protected static void parseJapeString(String japeRulesthrows ParseException {
1292     StringReader sr = new StringReader(japeRules);
1293     ParseCpsl parser = Factory.newJapeParser(sr, new HashMap<Object, Object>());
1294     Transducer transducer = parser.MultiPhaseTransducer();
1295     transducer.finish();
1296   }
1297 
1298   /* Set up for Runners */
1299 
1300   public static Test suite() {
1301     Test suite = new TestSetup(new TestSuite(TestConstraints.class)) {
1302       protected void setUp() {
1303         setUpGate();
1304         logger.info("GATE initialized and fixure set up.");
1305       }
1306     };
1307     return suite;
1308   }
1309 
1310   // main method for running this test as a standalone test
1311   public static void main(String[] args) {
1312     junit.textui.TestRunner.run(TestConstraints.suite());
1313   }
1314 // class TestJape