Search in sources :

Example 11 with TextClassificationException

use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.

the class InstanceExtractor method getSingleInstancePair.

private Instance getSingleInstancePair(Instance instance, JCas jcas) throws TextClassificationException {
    try {
        int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
        if (addInstanceId) {
            instance.addFeature(InstanceIdFeature.retrieve(jcas));
        }
        for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
            if (!(featExt instanceof PairFeatureExtractor)) {
                throw new TextClassificationException("Using non-pair FE in pair mode: " + featExt.getResourceName());
            }
            JCas view1 = jcas.getView(Constants.PART_ONE);
            JCas view2 = jcas.getView(Constants.PART_TWO);
            instance.setOutcomes(getOutcomes(jcas, null));
            instance.setWeight(getWeight(jcas, null));
            instance.setJcasId(jcasId);
            instance.addFeatures(((PairFeatureExtractor) featExt).extract(view1, view2));
        }
    } catch (CASException e) {
        throw new TextClassificationException(e);
    }
    return instance;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) PairFeatureExtractor(org.dkpro.tc.api.features.PairFeatureExtractor) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) JCas(org.apache.uima.jcas.JCas) CASException(org.apache.uima.cas.CASException) FeatureExtractorResource_ImplBase(org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)

Example 12 with TextClassificationException

use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.

the class InstanceExtractor method getOutcomes.

public List<String> getOutcomes(JCas jcas, AnnotationFS unit) throws TextClassificationException {
    Collection<TextClassificationOutcome> outcomes;
    if (unit == null) {
        outcomes = JCasUtil.select(jcas, TextClassificationOutcome.class);
    } else {
        outcomes = JCasUtil.selectCovered(jcas, TextClassificationOutcome.class, unit);
    }
    if (outcomes.size() == 0) {
        throw new TextClassificationException("No outcome annotations present in current CAS.");
    }
    List<String> stringOutcomes = new ArrayList<String>();
    for (TextClassificationOutcome outcome : outcomes) {
        stringOutcomes.add(outcome.getOutcome());
    }
    return stringOutcomes;
}
Also used : TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList)

Example 13 with TextClassificationException

use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.

the class PairReader_ImplBase method getNext.

@Override
public void getNext(JCas jcas) throws IOException, CollectionException {
    try {
        createMetaData(jcas, getCollectionId1() + "_" + getCollectionId2(), getDocumentId1() + "_" + getDocumentId2(), getTitle1() + " " + getTitle2());
        createView(PART_ONE, jcas, getLanguage1(), getText1(), getDocumentId1(), getTitle1());
        createView(PART_TWO, jcas, getLanguage2(), getText2(), getDocumentId2(), getTitle2());
    } catch (TextClassificationException e) {
        throw new CollectionException(e);
    } catch (CASException e) {
        throw new CollectionException(e);
    }
}
Also used : TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) CollectionException(org.apache.uima.collection.CollectionException) CASException(org.apache.uima.cas.CASException)

Example 14 with TextClassificationException

use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.

the class ContextCollectorUFE method extract.

// @Override
// public List<java.lang.Class<? extends MetaCollector>> getMetaCollectorClasses()
// {
// List<Class<? extends MetaCollector>> metaCollectorClasses = new ArrayList<Class<? extends
// MetaCollector>>();
// metaCollectorClasses.add(UnitContextMetaCollector.class);
// 
// return metaCollectorClasses;
// };
@Override
public Set<Feature> extract(JCas jcas, TextClassificationTarget unit) throws TextClassificationException {
    try {
        String idString = (String) InstanceIdFeature.retrieve(jcas, unit).getValue();
        ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
        if (DocumentMetaData.get(jcas).getIsLastSegment() == true) {
            bw.close();
        }
    } catch (IOException e) {
        throw new TextClassificationException(e);
    }
    return new HashSet<Feature>();
}
Also used : TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 15 with TextClassificationException

use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.

the class MetaInfoTask method getAnalysisEngineDescription.

@Override
public AnalysisEngineDescription getAnalysisEngineDescription(TaskContext aContext) throws ResourceInitializationException, IOException {
    featureExtractorNames = new HashSet<>();
    // check for error conditions
    if (featureExtractors == null) {
        throw new ResourceInitializationException(new TextClassificationException("No feature extractors have been added to the experiment."));
    }
    List<AnalysisEngineDescription> metaCollectors = new ArrayList<>();
    if (recordContext) {
        AnalysisEngineDescription aed = injectContextMetaCollector(aContext);
        if (aed == null) {
            throw new NullPointerException("Initializing a ContextMetaCollector returned an AnalysisEngineDescription which was [NULL]");
        }
        metaCollectors.add(aed);
    }
    try {
        // Configure the meta collectors for each feature extractor individually
        for (TcFeature feClosure : featureExtractors) {
            ExternalResourceDescription feDesc = feClosure.getActualValue();
            Class<?> feClass = getClass(feDesc);
            // Skip feature extractors that are not dependent on meta collectors
            if (!MetaDependent.class.isAssignableFrom(feClass)) {
                continue;
            }
            MetaDependent feInstance = (MetaDependent) feClass.newInstance();
            Map<String, Object> parameterSettings = ConfigurationParameterFactory.getParameterSettings(feDesc.getResourceSpecifier());
            validateUniqueFeatureExtractorNames(parameterSettings);
            // Tell the meta collectors where to store their data
            for (MetaCollectorConfiguration conf : feInstance.getMetaCollectorClasses(parameterSettings)) {
                configureStorageLocations(aContext, conf.descriptor, (String) feClosure.getId(), conf.collectorOverrides, AccessMode.READWRITE);
                metaCollectors.add(conf.descriptor);
            }
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new ResourceInitializationException(e);
    }
    // make sure that the meta key import can be resolved (even when no meta features have been
    // extracted, as in the regression demo)
    aContext.getFolder(META_KEY, AccessMode.READONLY);
    AggregateBuilder builder = new AggregateBuilder();
    for (AnalysisEngineDescription metaCollector : metaCollectors) {
        if (operativeViews != null) {
            for (String viewName : operativeViews) {
                builder.add(metaCollector, CAS.NAME_DEFAULT_SOFA, viewName);
            }
        } else {
            builder.add(metaCollector);
        }
    }
    return builder.createAggregateDescription();
}
Also used : TcFeature(org.dkpro.tc.api.features.TcFeature) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) ArrayList(java.util.ArrayList) MetaDependent(org.dkpro.tc.api.features.meta.MetaDependent) AggregateBuilder(org.apache.uima.fit.factory.AggregateBuilder) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) MetaCollectorConfiguration(org.dkpro.tc.api.features.meta.MetaCollectorConfiguration) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Aggregations

TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)25 ArrayList (java.util.ArrayList)10 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)7 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)6 IOException (java.io.IOException)5 Feature (org.dkpro.tc.api.features.Feature)5 File (java.io.File)4 JCas (org.apache.uima.jcas.JCas)4 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)4 FeatureExtractorResource_ImplBase (org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)4 JCasId (org.dkpro.tc.api.type.JCasId)4 TextClassificationOutcome (org.dkpro.tc.api.type.TextClassificationOutcome)4 CASException (org.apache.uima.cas.CASException)3 PairFeatureExtractor (org.dkpro.tc.api.features.PairFeatureExtractor)3 FrequencyDistribution (de.tudarmstadt.ukp.dkpro.core.api.frequency.util.FrequencyDistribution)2 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 SimilarityException (dkpro.similarity.algorithms.api.SimilarityException)2 HashSet (java.util.HashSet)2 FeatureExtractor (org.dkpro.tc.api.features.FeatureExtractor)2 Instance (org.dkpro.tc.api.features.Instance)2