Java Code Examples for org.apache.uima.cas.CAS#addFsToIndexes()
The following examples show how to use
org.apache.uima.cas.CAS#addFsToIndexes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CasMergeTest.java From webanno with Apache License 2.0 | 6 votes |
@Test public void simpleCopyToDiffExistingAnnoWithNoStackingTest() throws Exception { CAS jcas = createJCas().getCas(); Type type = jcas.getTypeSystem().getType(POS.class.getTypeName()); AnnotationFS clickedFs = createPOSAnno(jcas, "NN", 0, 0); CAS mergeCAs = createJCas().getCas(); AnnotationFS existingFs = mergeCAs.createAnnotation(type, 0, 0); Feature posValue = type.getFeatureByBaseName("PosValue"); existingFs.setStringValue(posValue, "NE"); mergeCAs.addFsToIndexes(existingFs); sut.mergeSpanAnnotation(null, null, posLayer, mergeCAs, clickedFs, false); assertEquals(1, CasUtil.selectCovered(mergeCAs, type, 0, 0).size()); }
Example 2
Source File: ParagraphAnnotator.java From biomedicus with Apache License 2.0 | 6 votes |
@Override public void process(CAS aCAS) { LOGGER.trace("Annotating rtf paragraphs."); CAS systemView = aCAS.getView(documentName); Type newParagraphType = systemView.getTypeSystem() .getType("biomedicus.v2.rtf.NewParagraph"); Type paragraphType = systemView.getTypeSystem() .getType("biomedicus.v2.Paragraph"); AnnotationIndex<AnnotationFS> newParagraphIndex = systemView .getAnnotationIndex(newParagraphType); int start = 0; for (AnnotationFS newParagraph : newParagraphIndex) { int end = newParagraph.getEnd(); systemView.addFsToIndexes( systemView.createAnnotation(paragraphType, start, end)); start = end; } }
Example 3
Source File: RelationAdapter.java From webanno with Apache License 2.0 | 6 votes |
private AnnotationFS createRelationAnnotation(CAS cas, AnnotationFS originFS, AnnotationFS targetFS) throws AnnotationException { if (targetFS == null || originFS == null) { throw new IllegalPlacementException("Relation must have a source and a target!"); } // Set the relation offsets in DKPro Core style - the relation recieves the offsets from // the dependent // If origin and target spans are multiple tokens, dependentFS.getBegin will be the // the begin position of the first token and dependentFS.getEnd will be the End // position of the last token. final Type type = getType(cas, getLayer().getName()); final Feature dependentFeature = type.getFeatureByBaseName(targetFeatureName); final Feature governorFeature = type.getFeatureByBaseName(sourceFeatureName); AnnotationFS newAnnotation = cas.createAnnotation(type, targetFS.getBegin(), targetFS.getEnd()); newAnnotation.setFeatureValue(dependentFeature, targetFS); newAnnotation.setFeatureValue(governorFeature, originFS); cas.addFsToIndexes(newAnnotation); return newAnnotation; }
Example 4
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 6 votes |
@Test public void testZeroLengthSpansWithoutFeatures() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); Type simpleSpanType = cas.getTypeSystem().getType("webanno.custom.SimpleSpan"); // One at the beginning AnnotationFS fs1 = cas.createAnnotation(simpleSpanType, 0, 0); cas.addFsToIndexes(fs1); // One at the end AnnotationFS fs2 = cas.createAnnotation(simpleSpanType, jcas.getDocumentText().length(), jcas.getDocumentText().length()); cas.addFsToIndexes(fs2); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan")); }
Example 5
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testSingleNonTokenRelationWithoutFeature() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(tokens.size() - 1); Span gov = new Span(jcas, t1.getBegin(), t1.getEnd()); gov.addToIndexes(); Span dep = new Span(jcas, t2.getBegin(), t2.getEnd()); dep.addToIndexes(); Type relationType = cas.getTypeSystem().getType("webanno.custom.SimpleRelation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(Span.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.SimpleRelation")); }
Example 6
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testSingleStackedNonTokenRelationWithoutFeatureValue3() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(tokens.size() - 1); Span gov = new Span(jcas, t1.getBegin(), t1.getEnd()); gov.addToIndexes(); new Span(jcas, t1.getBegin(), t1.getEnd()).addToIndexes(); Span dep = new Span(jcas, t2.getBegin(), t2.getEnd()); dep.addToIndexes(); Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(Span.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.Relation")); }
Example 7
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testSingleNonMultiTokenRelationWithMultipleFeatureValues() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(1); Token t3 = tokens.get(2); Token t4 = tokens.get(3); Span gov = new Span(jcas, t1.getBegin(), t2.getEnd()); gov.addToIndexes(); Span dep = new Span(jcas, t3.getBegin(), t4.getEnd()); dep.addToIndexes(); Type relationType = cas.getTypeSystem().getType("webanno.custom.ComplexRelation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); FSUtil.setFeature(fs1, "value", "nsubj"); FSUtil.setFeature(fs1, "boolValue", true); FSUtil.setFeature(fs1, "integerValue", 42); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(Span.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.ComplexRelation")); }
Example 8
Source File: AllAnnotationsIndexedCheckTest.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testOK() throws Exception { TypeSystemDescription tsd = UIMAFramework.getResourceSpecifierFactory() .createTypeSystemDescription(); String refTypeName = "RefType"; TypeDescription refTypeDesc = tsd.addType(refTypeName, null, CAS.TYPE_NAME_ANNOTATION); refTypeDesc.addFeature("ref", null, CAS.TYPE_NAME_ANNOTATION); CAS cas = CasCreationUtils.createCas(tsd, null, null); Type refType = cas.getTypeSystem().getType(refTypeName); // A regular index annotation AnnotationFS anno1 = cas.createAnnotation(cas.getAnnotationType(), 0, 1); cas.addFsToIndexes(anno1); // An indexed annotation but reachable through an indexe one (below) AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1); cas.addFsToIndexes(anno2); // An indexed annotation that references the non-indexed annotation above AnnotationFS anno3 = cas.createAnnotation(refType, 0, 1); anno3.setFeatureValue(refType.getFeatureByBaseName("ref"), anno2); cas.addFsToIndexes(anno3); List<LogMessage> messages = new ArrayList<>(); CasDoctor cd = new CasDoctor(AllFeatureStructuresIndexedCheck.class); // A project is not required for this check boolean result = cd.analyze(null, cas, messages); messages.forEach(System.out::println); assertTrue(result); }
Example 9
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testSingleNonTokenRelationWithoutFeatureValue() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(tokens.size() - 1); Span gov = new Span(jcas, t1.getBegin(), t1.getEnd()); gov.addToIndexes(); Span dep = new Span(jcas, t2.getBegin(), t2.getEnd()); dep.addToIndexes(); Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(Span.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.Relation")); }
Example 10
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testZeroLengthSlotFeature2() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(1); Token t3 = tokens.get(2); Type type = cas.getTypeSystem().getType("webanno.custom.SimpleSpan"); AnnotationFS s2 = cas.createAnnotation(type, t2.getBegin(), t3.getEnd()); cas.addFsToIndexes(s2); AnnotationFS s3 = cas.createAnnotation(type, t3.getEnd(), t3.getEnd()); cas.addFsToIndexes(s3); FeatureStructure link1 = makeLinkFS(jcas, "p1", s2); FeatureStructure link2 = makeLinkFS(jcas, "p2", s3); makeLinkHostFS(jcas, t1.getBegin(), t1.getEnd(), link1, link2); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.SimpleLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.SimpleLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"), WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan")); }
Example 11
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Ignore("Relations between different layers not supported in WebAnno TSV 3 atm") @Test public void testSingleMixedRelationWithoutFeatureValue() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token gov = tokens.get(0); Token t2 = tokens.get(tokens.size() - 1); Span dep = new Span(jcas, t2.getBegin(), t2.getEnd()); dep.addToIndexes(); Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(Span.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.Relation")); }
Example 12
Source File: AllAnnotationsIndexedCheckTest.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testFail() throws Exception { TypeSystemDescription tsd = UIMAFramework.getResourceSpecifierFactory() .createTypeSystemDescription(); String refTypeName = "RefType"; TypeDescription refTypeDesc = tsd.addType(refTypeName, null, CAS.TYPE_NAME_ANNOTATION); refTypeDesc.addFeature("ref", null, CAS.TYPE_NAME_ANNOTATION); CAS cas = CasCreationUtils.createCas(tsd, null, null); Type refType = cas.getTypeSystem().getType(refTypeName); // A regular index annotation AnnotationFS anno1 = cas.createAnnotation(cas.getAnnotationType(), 0, 1); cas.addFsToIndexes(anno1); // A non-index annotation but reachable through an indexe one (below) AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1); // An indexed annotation that references the non-indexed annotation above AnnotationFS anno3 = cas.createAnnotation(refType, 0, 1); anno3.setFeatureValue(refType.getFeatureByBaseName("ref"), anno2); cas.addFsToIndexes(anno3); List<LogMessage> messages = new ArrayList<>(); CasDoctor cd = new CasDoctor(AllFeatureStructuresIndexedCheck.class); // A project is not required for this check boolean result = cd.analyze(null, cas, messages); messages.forEach(System.out::println); assertFalse(result); }
Example 13
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testSimpleSlotFeatureWithoutValues() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(1); Token t3 = tokens.get(2); Type type = cas.getTypeSystem().getType("webanno.custom.SimpleSpan"); AnnotationFS s2 = cas.createAnnotation(type, t2.getBegin(), t2.getEnd()); cas.addFsToIndexes(s2); AnnotationFS s3 = cas.createAnnotation(type, t3.getBegin(), t3.getEnd()); cas.addFsToIndexes(s3); FeatureStructure link1 = makeLinkFS(jcas, null, s2); FeatureStructure link2 = makeLinkFS(jcas, null, s3); makeLinkHostFS(jcas, t1.getBegin(), t1.getEnd(), link1, link2); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.SimpleLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.SimpleLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"), WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan")); }
Example 14
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 5 votes |
@Test public void testSimpleCrossSenenceSlotFeature() throws Exception { JCas jcas = makeJCasTwoSentences(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(1); Token t3 = tokens.get(6); Type type = cas.getTypeSystem().getType("webanno.custom.SimpleSpan"); AnnotationFS s2 = cas.createAnnotation(type, t2.getBegin(), t2.getEnd()); cas.addFsToIndexes(s2); AnnotationFS s3 = cas.createAnnotation(type, t3.getBegin(), t3.getEnd()); cas.addFsToIndexes(s3); FeatureStructure link1 = makeLinkFS(jcas, "p1", s2); FeatureStructure link2 = makeLinkFS(jcas, "p2", s3); makeLinkHostFS(jcas, t1.getBegin(), t1.getEnd(), link1, link2); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.SimpleLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.SimpleLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"), WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan")); }
Example 15
Source File: OpenNlpDoccatRecommender.java From inception with Apache License 2.0 | 5 votes |
@Override public void predict(RecommenderContext aContext, CAS aCas) throws RecommendationException { DoccatModel model = aContext.get(KEY_MODEL).orElseThrow(() -> new RecommendationException("Key [" + KEY_MODEL + "] not found in context")); DocumentCategorizerME finder = new DocumentCategorizerME(model); Type sentenceType = getType(aCas, Sentence.class); Type predictedType = getPredictedType(aCas); Type tokenType = getType(aCas, Token.class); Feature scoreFeature = getScoreFeature(aCas); Feature predictedFeature = getPredictedFeature(aCas); Feature isPredictionFeature = getIsPredictionFeature(aCas); int predictionCount = 0; for (AnnotationFS sentence : select(aCas, sentenceType)) { if (predictionCount >= traits.getPredictionLimit()) { break; } predictionCount++; List<AnnotationFS> tokenAnnotations = selectCovered(tokenType, sentence); String[] tokens = tokenAnnotations.stream() .map(AnnotationFS::getCoveredText) .toArray(String[]::new); double[] outcome = finder.categorize(tokens); String label = finder.getBestCategory(outcome); AnnotationFS annotation = aCas.createAnnotation(predictedType, sentence.getBegin(), sentence.getEnd()); annotation.setStringValue(predictedFeature, label); annotation.setDoubleValue(scoreFeature, NumberUtils.max(outcome)); annotation.setBooleanValue(isPredictionFeature, true); aCas.addFsToIndexes(annotation); } }
Example 16
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testOutOfTypeSystemListElement() throws Exception { //add to type system an annotation type that has an FSList feature TypeDescription testAnnotTypeDesc = typeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation"); testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList"); //populate a CAS with such an list CAS cas = CasCreationUtils.createCas(typeSystem, null, null); Type testAnnotType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation"); Type orgType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.Organization"); AnnotationFS orgAnnot1 = cas.createAnnotation(orgType, 0, 10); cas.addFsToIndexes(orgAnnot1); AnnotationFS orgAnnot2 = cas.createAnnotation(orgType, 10, 20); cas.addFsToIndexes(orgAnnot2); AnnotationFS testAnnot = cas.createAnnotation(testAnnotType, 0, 20); cas.addFsToIndexes(testAnnot); Type nonEmptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST); Type emptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_EMPTY_FS_LIST); Feature headFeat = nonEmptyFsListType.getFeatureByBaseName("head"); Feature tailFeat = nonEmptyFsListType.getFeatureByBaseName("tail"); FeatureStructure emptyNode = cas.createFS(emptyFsListType); FeatureStructure secondNode = cas.createFS(nonEmptyFsListType); secondNode.setFeatureValue(headFeat, orgAnnot2); secondNode.setFeatureValue(tailFeat, emptyNode); FeatureStructure firstNode = cas.createFS(nonEmptyFsListType); firstNode.setFeatureValue(headFeat, orgAnnot1); firstNode.setFeatureValue(tailFeat, secondNode); Feature listFeat = testAnnotType.getFeatureByBaseName("listFeat"); testAnnot.setFeatureValue(listFeat, firstNode); //serialize to XMI String xmiStr = serialize(cas, null); // System.out.println(xmiStr); //deserialize into a CAS that's missing the Organization type File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml"); TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(partialTypeSystemFile)); testAnnotTypeDesc = partialTypeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation"); testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList"); CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, null); XmiSerializationSharedData sharedData = new XmiSerializationSharedData(); deserialize(xmiStr, partialTsCas, sharedData, true, -1); //check out of type system data Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation"); FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get(); Feature listFeat2 = testAnnotType2.getFeatureByBaseName("listFeat"); FeatureStructure listFs = testAnnot2.getFeatureValue(listFeat2); List ootsElems = sharedData.getOutOfTypeSystemElements(); assertEquals(2, ootsElems.size()); OotsElementData oed = sharedData.getOutOfTypeSystemFeatures((TOP) listFs); XmlAttribute attr = oed.attributes.get(0); assertNotNull(attr); assertEquals(CAS.FEATURE_BASE_NAME_HEAD, attr.name); assertEquals(attr.value, ((OotsElementData)ootsElems.get(0)).xmiId); //reserialize along with out of type system data String xmiStr2 = serialize(partialTsCas, sharedData); // System.out.println(xmiStr2); //deserialize into a new CAS and compare CAS cas2 = CasCreationUtils.createCas(typeSystem, null, null); deserialize(xmiStr2, cas2, null, false, -1); CasComparer.assertEquals(cas, cas2); }
Example 17
Source File: WebAnnoTsv3WriterTestBase.java From webanno with Apache License 2.0 | 4 votes |
@Test public void testStackedNonMultiTokenRelationWithMultipleFeatureValues() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(1); Token t3 = tokens.get(2); Token t4 = tokens.get(3); Span gov = new Span(jcas, t1.getBegin(), t2.getEnd()); gov.addToIndexes(); Span dep = new Span(jcas, t3.getBegin(), t4.getEnd()); dep.addToIndexes(); Type relationType = cas.getTypeSystem().getType("webanno.custom.ComplexRelation"); // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); FSUtil.setFeature(fs1, "value", "nsubj"); FSUtil.setFeature(fs1, "boolValue", true); FSUtil.setFeature(fs1, "integerValue", 42); cas.addFsToIndexes(fs1); // WebAnno legacy conventions // AnnotationFS fs2 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs2 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs2, "Governor", gov); FSUtil.setFeature(fs2, "Dependent", dep); FSUtil.setFeature(fs2, "value", "obj"); FSUtil.setFeature(fs2, "boolValue", false); FSUtil.setFeature(fs2, "integerValue", 43); cas.addFsToIndexes(fs2); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(Span.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.ComplexRelation")); }
Example 18
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
private AnnotationFS createPersonAnnot(CAS cas, int begin, int end) { Type personType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.Person"); AnnotationFS person = cas.createAnnotation(personType, begin, end); cas.addFsToIndexes(person); return person; }
Example 19
Source File: ComplexTypeTest.java From webanno with Apache License 2.0 | 4 votes |
@Test public void testProfType() throws Exception { TypeSystemDescription tsd = TypeSystemDescriptionFactory .createTypeSystemDescription("desc.types.TestTypeSystemDescriptor"); CAS cas = CasCreationUtils.createCas(tsd, null, null); cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes."); TypeSystem ts = cas.getTypeSystem(); Type profType = ts.getType("de.tud.Prof"); Feature profNameFeature = profType.getFeatureByBaseName("fullName"); Feature profBossFeature = profType.getFeatureByBaseName("boss"); AnnotationFS proemel = cas.createAnnotation(profType, 0, 0); proemel.setStringValue(profNameFeature, "Hans Juergen Proeml"); cas.addFsToIndexes(proemel); AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38); gurevych.setStringValue(profNameFeature, "Iryna Gurevych"); gurevych.setFeatureValue(profBossFeature, proemel); cas.addFsToIndexes(gurevych); /* * for (String feature : Arrays.asList("fullName", "boss")) { Feature someFeature = * gurevych.getType().getFeatureByBaseName(feature); if * (someFeature.getRange().isPrimitive()) { String value = * gurevych.getFeatureValueAsString(someFeature); System.out.println(value); } else { * FeatureStructure value = gurevych.getFeatureValue(someFeature); * System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature), * value.getType()); } } */ ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream( "src/test/resources/rules/prof.rules")); Parse p = parser.Parse(); ParsedConstraints constraints = p.accept(new ParserVisitor()); Evaluator constraintsEvaluator = new ValuesGenerator(); List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(gurevych, "professorName", constraints); List<PossibleValue> exValues = new LinkedList<>(); exValues.add(new PossibleValue("Iryna Gurevych", false)); assertEquals(possibleValues, exValues); }
Example 20
Source File: TestAnnotator.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void process(CAS cas) { FeatureStructure fs = cas.createFS(cas.getTypeSystem().getType(CAS.TYPE_NAME_ANNOTATION_BASE)); cas.addFsToIndexes(fs); fs = cas.createFS(cas.getTypeSystem().getType("OtherAnnotation")); cas.addFsToIndexes(fs); }