/** * Serializes a CAS in the given format. * * @param jcas * CAS (Common Analysis System) to be serialized. * @param type * type of cTAKES (UIMA) serializer used to write CAS. * @param prettyPrint * {@code true} to do pretty printing of output. * @param stream * {@link OutputStream} object used to print out information * extracted by using cTAKES. * @throws SAXException * if there was a SAX exception. * @throws IOException * if any I/O error occurs. */ public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint, OutputStream stream) throws SAXException, IOException { if (type == CTAKESSerializer.XCAS) { XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint); } else if (type == CTAKESSerializer.XMI) { XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream, prettyPrint, new XmiSerializationSharedData()); } else { XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream); } }
/** * Get the CAS type for the given JCas wrapper class type. * * @param jCas * the JCas containing the type system. * @param type * the JCas wrapper class type. * @return the CAS type. */ public static Type getType(JCas jCas, Class<?> type) { return CasUtil.getType(jCas.getCas(), type); }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { Collection<AnnotationFS> sequences = CasUtil.select(aJCas.getCas(), sequenceSpanType); for (AnnotationFS s : sequences) { int seqSize = CasUtil.selectCovered(aJCas.getCas(), instanceType, s).size(); if (seqSize > maximumLength) { maximumLength = seqSize; } } }
protected void initCas(JCas aJCas, FileResource aResource) { super.initCas(aJCas.getCas(), aResource, null); } }
/** * Set the primary Uniform Resource Identifier for this JCas and all its views. This creates the * view {@link #URI} and assigns the URI there. * * @param jCas * The CAS object. * @param uri * The primary URI for the CAS and all its views. */ public static void setURI(JCas jCas, java.net.URI uri) { ViewUriUtil.setURI(jCas.getCas(), uri); }
private static Collection<AnnotationFS> getAllAnnoFss(JCas aJcas, Type aType) { Collection<AnnotationFS> spanAnnos = select(aJcas.getCas(), aType); new ArrayList<>(spanAnnos).sort(Comparator.comparingInt(AnnotationFS::getBegin)); return spanAnnos; }
private List<String> getItems(JCas view) throws FeaturePathException { List<String> items = new ArrayList<String>(); for (Map.Entry<AnnotationFS, String> entry : FeaturePathFactory.select(view.getCas(), segmentFeaturePath)) { items.add(entry.getValue()); } return items; } }
/** * Create a new link annotation. Already adds the chain to the CAS. */ private AnnotationFS newLink(JCas aJCas, int aBegin, int aEnd) { Type linkType = CasUtil.getType(aJCas.getCas(), getAnnotationTypeName()); AnnotationFS newLink = aJCas.getCas().createAnnotation(linkType, aBegin, aEnd); aJCas.getCas().addFsToIndexes(newLink); return newLink; }
@Override public void getNext(JCas jCas) throws IOException, CollectionException { FileInputStream inputStream = new FileInputStream(this.filesIter.next()); try { XmiCasDeserializer.deserialize(new BufferedInputStream(inputStream), jCas.getCas()); } catch (SAXException e) { throw new CollectionException(e); } finally { inputStream.close(); } this.completed += 1; }
public static void clearAnnotations(JCas aJCas, Type aType) throws IOException { List<AnnotationFS> annotationsToRemove = new ArrayList<>(); annotationsToRemove.addAll(select(aJCas.getCas(), aType)); for (AnnotationFS annotation : annotationsToRemove) { aJCas.removeFsFromIndexes(annotation); } }
public void process(JCas jCas) throws AnalysisEngineProcessException { CAS cas = jCas.getCas(); Type type = CasUtil.getAnnotationType(cas, printTypeName); Collection<AnnotationFS> annotations = CasUtil.select(cas, type); System.out.println(indication+"\n Here is a list of annotation '" + printTypeName + "':"); for (AnnotationFS annotation : annotations) { System.out.println(annotation.toString() + " Covered Text: \"" + annotation.getCoveredText() + "\""); } } }
@Override public void init(JCas aJCas) { sentences = select(aJCas, Sentence.class).iterator(); CAS cas = aJCas.getCas(); Type chunkType = CasUtil.getType(cas, Chunk.class); Feature chunkTagFeature = chunkType.getFeatureByBaseName("chunkValue"); chunkEncoder = new IobEncoder(cas, chunkType, chunkTagFeature); }
/** * Create a new chain head feature structure. Already adds the chain to the CAS. */ private FeatureStructure newChain(JCas aJCas, AnnotationFS aFirstLink) { Type chainType = getAnnotationType(aJCas.getCas()); FeatureStructure newChain = aJCas.getCas().createFS(chainType); newChain.setFeatureValue(chainType.getFeatureByBaseName(chainFirstFeatureName), aFirstLink); aJCas.addFsToIndexes(newChain); return newChain; }
@Override public List<String> getAnnotation(JCas aJcas, AnnotationFeature aFeature, int begin, int end) { Type type = getType(aJcas.getCas(), getAnnotationTypeName()); List<String> annotations = new ArrayList<String>(); for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, begin, end)) { Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName()); annotations.add(fs.getFeatureValueAsString(labelFeature)); } return annotations; }
/** * Get an annotation using the begin/offsets and its type */ public static AnnotationFS selectSingleFsAt(JCas aJcas, Type aType, int aBegin, int aEnd) { for (AnnotationFS anFS : selectCovered(aJcas.getCas(), aType, aBegin, aEnd)) { if (anFS.getBegin() == aBegin && anFS.getEnd() == aEnd) { return anFS; } } return null; }
private static List<AnnotationFS> getRelAnnosOnPosition(AnnotationFS aFs, AnnotationFS aOriginFs, AnnotationFS aTargetFs, JCas aJcas) { Type type = aFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); return selectCovered(aJcas.getCas(), type, aFs.getBegin(), aFs.getEnd()).stream() .filter(fs -> fs.getFeatureValue(sourceFeat).equals(aOriginFs) && fs.getFeatureValue(targetFeat).equals(aTargetFs)) .collect(Collectors.toList()); }
public AnnotationFS handle(CreateSpanAnnotationRequest aRequest) throws AnnotationException { CreateSpanAnnotationRequest request = aRequest; for (SpanLayerBehavior behavior : behaviors) { request = behavior.onCreate(this, request); } AnnotationFS newAnnotation = createSpanAnnotation(request.getJcas().getCas(), request.getBegin(), request.getEnd()); publishEvent(new SpanCreatedEvent(this, request.getDocument(), request.getUsername(), newAnnotation)); return newAnnotation; }
@Test public void testCreateFileDefaultDirectory() throws Exception { BaleenCollectionReader bcr = getCollectionReader(); assertTrue( bcr.doHasNext()); // There will be files in the current directory, so we can just check // that it's picked them up. bcr.getNext(jCas.getCas()); assertTrue(getSource(jCas).contains(System.getProperty("user.dir"))); bcr.close(); }
private void assertNextSourceNotNull(BaleenCollectionReader bcr) throws Exception { assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertNotNull(getSource(jCas)); jCas.reset(); }
@Test public void test() throws Exception { BaleenCollectionReader bcr = getCollectionReader(); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertFalse(jCas.getDocumentText().isEmpty()); assertFalse(bcr.doHasNext()); bcr.close(); } }