/** * 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); } }
/** * Constructor * * <p>Type system provided by {@link JCasFactory} * * @param includedTypeNames The (full) class names of the types to convert (eg * Person.class.getName()) * @throws UIMAException if type system can not be created */ public TaxonomyFactory(String[] includedTypeNames) throws UIMAException { this(JCasFactory.createJCas().getTypeSystem(), includedTypeNames); }
/** * For a given type name, look through the type system and return the matching class. If two types * of the same name (but different packages) exist, then null will be returned and the package * will need to be included in the typeName. * * @param typeName The name of the type, optionally including the package * @param jCas A JCas object containing the type system * @return The class associated with that type */ public static Class<? extends AnnotationBase> getType(String typeName, JCas jCas) { return getType(typeName, jCas.getTypeSystem()); }
public static Type getType(JCas jcas, String typeName) { TypeSystem ts = jcas.getTypeSystem(); return ts.getType(typeName); } }
public static Type getType(JCas jcas, String typeName) { TypeSystem ts = jcas.getTypeSystem(); return ts.getType(typeName); } }
/** * Constructor * * <p>Type system provided by {@link JCasFactory} * * @param includedTypeNames The (full) class names of the types to convert (eg * Person.class.getName()) * @throws UIMAException if type system can not be created */ public TaxonomyFactory(String[] includedTypeNames) throws UIMAException { this(JCasFactory.createJCas().getTypeSystem(), includedTypeNames); }
@Override public TypeSystem getTypeSystem() throws CASRuntimeException { testLiveness(); return delegate.getTypeSystem(); }
private Type getClassType(Class<? extends Annotation> cls) { for(Type type:Lists.newArrayList(actual.getTypeSystem().getTypeIterator())) { if(type.getName().equals(cls.getName())) return type; } throw new IllegalArgumentException("No type found for class: " + cls.getName()); }
public static void copyAttributes(Element element, Annotation annotation, JCas jCas) { for (NamePair names : timemlAttributeLists.get(element.getName().toUpperCase())) { String featureValue = element.getAttributeValue(names.timemlName); if (featureValue != null) { String className = annotation.getClass().getName(); String uimaName = String.format("%s:%s", className, names.uimaName); Feature feature = jCas.getTypeSystem().getFeatureByFullName(uimaName); annotation.setFeatureValueFromString(feature, featureValue); } } }
public static void removeInconsistentAttributes(Element element, Annotation annotation, JCas jCas) { for (NamePair names : timemlAttributeLists.get(element.getName().toUpperCase())) { String newValue = element.getAttributeValue(names.timemlName); String className = annotation.getClass().getName(); String uimaName = String.format("%s:%s", className, names.uimaName); Feature feature = jCas.getTypeSystem().getFeatureByFullName(uimaName); String oldValue = annotation.getFeatureValueAsString(feature); if (oldValue != null && !oldValue.equals(newValue)) { annotation.setFeatureValueFromString(feature, null); } } }
public static void removeInconsistentAttributes(Element element, Annotation annotation, JCas jCas) { for (NamePair names : timemlAttributeLists.get(element.getName().toUpperCase())) { String newValue = element.getAttributeValue(names.timemlName); String className = annotation.getClass().getName(); String uimaName = String.format("%s:%s", className, names.uimaName); Feature feature = jCas.getTypeSystem().getFeatureByFullName(uimaName); String oldValue = annotation.getFeatureValueAsString(feature); if (oldValue != null && !oldValue.equals(newValue)) { annotation.setFeatureValueFromString(feature, null); } } }
private Type getType(String annotationType) { for(Type type:Lists.newArrayList(actual.getTypeSystem().getTypeIterator())) { if(type.getName().equals(annotationType)) return type; else if(type.getShortName().equals(annotationType)) return type; } throw new IllegalArgumentException("No such type found: " + annotationType); }
public static Annotation getFirst(JCas jcas, String typeName) { TypeSystem ts = jcas.getTypeSystem(); Type type = ts.getType(typeName); AnnotationIndex<Annotation> index = jcas.getAnnotationIndex(type); FSIterator<Annotation> iterator = index.iterator(); if (iterator.hasNext()) { return (Annotation) iterator.next(); } return null; }
private AnnotationFS createTokenAnno(JCas aJCas, int aBegin, int aEnd) { Type type = aJCas.getTypeSystem().getType(Token.class.getTypeName()); AnnotationFS token = aJCas.getCas().createAnnotation(type, aBegin, aEnd); aJCas.addFsToIndexes(token); return token; }
@Test public void testAnalyze() throws Exception { JCas jcas = JCasFactory.createJCas(); TsvSchema schema = Tsv3XCasSchemaAnalyzer.analyze(jcas.getTypeSystem()); for (TsvColumn col : schema.getColumns()) { System.out.println(col); } } }
private AnnotationFS createPOSAnno(JCas aJCas, String aValue, int aBegin, int aEnd) { Type type = aJCas.getTypeSystem().getType(POS.class.getTypeName()); AnnotationFS clickedFs = aJCas.getCas().createAnnotation(type, aBegin, aEnd); Feature posValue = type.getFeatureByBaseName("PosValue"); clickedFs.setStringValue(posValue, aValue); aJCas.addFsToIndexes(clickedFs); return clickedFs; }
private static AnnotationFS makeLinkHostFS(JCas aJCas, String aType, int aBegin, int aEnd, FeatureStructure... aLinks) { Type hostType = aJCas.getTypeSystem().getType(aType); AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd); if (aLinks != null) { hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"), FSCollectionFactory.createFSArray(aJCas, asList(aLinks))); } aJCas.getCas().addFsToIndexes(hostA1); return hostA1; }
public static void makeLinkHostFS(JCas aJCas, int aBegin, int aEnd, FeatureStructure... aLinks) { Type hostType = aJCas.getTypeSystem().getType(HOST_TYPE); AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd); hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"), FSCollectionFactory.createFSArray(aJCas, asList(aLinks))); aJCas.getCas().addFsToIndexes(hostA1); }
public static AnnotationFS makeLinkHostMultiSPanFeatureFS(JCas aJCas, int aBegin, int aEnd, Feature aSpanFeature, String aValue, FeatureStructure... aLinks) { Type hostType = aJCas.getTypeSystem().getType(HOST_TYPE); AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd); hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"), FSCollectionFactory.createFSArray(aJCas, asList(aLinks))); hostA1.setStringValue(aSpanFeature, aValue); aJCas.getCas().addFsToIndexes(hostA1); return hostA1; }
private static FeatureStructure makeLinkFS(JCas aJCas, String aType, String aSlotLabel, AnnotationFS aTarget) { Type linkType = aJCas.getTypeSystem().getType(aType); FeatureStructure linkA1 = aJCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), aTarget); aJCas.getCas().addFsToIndexes(linkA1); return linkA1; }