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;
}
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;
}
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);
}
}
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>();
}
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();
}
Aggregations