use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.
the class InstanceExtractor method getSingleInstanceDocument.
private Instance getSingleInstanceDocument(Instance instance, JCas jcas, boolean supportSparseFeatures) throws TextClassificationException {
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
TextClassificationTarget documentTcu = JCasUtil.selectSingle(jcas, TextClassificationTarget.class);
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas));
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (!(featExt instanceof FeatureExtractor)) {
throw new TextClassificationException("Using incompatible feature in document mode: " + featExt.getResourceName());
}
if (supportSparseFeatures) {
instance.addFeatures(getSparse(jcas, documentTcu, featExt));
} else {
instance.addFeatures(getDense(jcas, documentTcu, featExt));
}
instance.setOutcomes(getOutcomes(jcas, null));
instance.setWeight(getWeight(jcas, null));
instance.setJcasId(jcasId);
}
return instance;
}
use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.
the class ValidityCheckConnector method checkErrorConditionCasHasTwoVies.
private void checkErrorConditionCasHasTwoVies(JCas jcas) throws AnalysisEngineProcessException {
try {
jcas.getView(Constants.PART_ONE);
jcas.getView(Constants.PART_TWO);
} catch (CASException e) {
throw new AnalysisEngineProcessException(new TextClassificationException("Your experiment is configured to be pair classification, but I could not find the two views " + Constants.PART_ONE + " and " + Constants.PART_TWO + ". Please use a reader that inhereits from " + Constants.class.getName()));
}
}
use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.
the class ValidityCheckConnectorPost method checkErrorConditionMissingOutcomeForTargetIfUnitOrSequenceMode.
private void checkErrorConditionMissingOutcomeForTargetIfUnitOrSequenceMode(List<TextClassificationTarget> targets, List<TextClassificationOutcome> outcomes) throws AnalysisEngineProcessException {
// labeled with an outcome annotation
if (featureModeI == 2 || featureModeI == 4) {
if (targets.size() == 0) {
throw new AnalysisEngineProcessException(new TextClassificationException("Your experiment is supposed to have [+" + TextClassificationTarget.class.getName() + "] annotations, which are missing"));
} else {
if (targets.size() != outcomes.size()) {
throwException("Number of targets [" + targets.size() + "] != number of outcomes [" + outcomes.size() + "]");
}
for (int i = 0; i < targets.size(); i++) {
TextClassificationTarget t = targets.get(i);
TextClassificationOutcome o = outcomes.get(i);
if (t.getBegin() != o.getBegin() || t.getEnd() != o.getEnd()) {
throwException("Index of target and outcome do not match taget span: [" + t.getBegin() + " - " + t.getEnd() + "] != outcome span " + o.getBegin() + " - " + o.getEnd());
}
}
}
}
}
use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.
the class IdfPairMetaCollector method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
JCas view1;
JCas view2;
try {
view1 = jcas.getView(PART_ONE);
view2 = jcas.getView(PART_TWO);
} catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
FrequencyDistribution<String> document1NGrams;
FrequencyDistribution<String> document2NGrams;
try {
document1NGrams = getNgramsFD(view1);
document2NGrams = getNgramsFD(view2);
} catch (TextClassificationException e) {
throw new AnalysisEngineProcessException(e);
}
FrequencyDistribution<String> documentNGrams = new FrequencyDistribution<String>();
// This is different than other metacollectors.
for (String key : document1NGrams.getKeys()) {
documentNGrams.addSample(key, 1);
}
for (String key : document2NGrams.getKeys()) {
documentNGrams.addSample(key, 1);
}
for (String ngram : documentNGrams.getKeys()) {
for (int i = 0; i < documentNGrams.getCount(ngram); i++) {
Field field = new Field(getFieldName(), ngram, fieldType);
currentDocument.add(field);
}
}
try {
writeToIndex();
} catch (IOException e) {
throw new AnalysisEngineProcessException(e);
}
}
use of org.dkpro.tc.api.exception.TextClassificationException in project dkpro-tc by dkpro.
the class LibsvmDataFormatSerializeModelConnector method trainAndStoreModel.
private void trainAndStoreModel(TaskContext aContext) throws Exception {
boolean multiLabel = learningMode.equals(Constants.LM_MULTI_LABEL);
if (multiLabel) {
throw new TextClassificationException("Multi-label is not yet implemented");
}
File fileTrain = getTrainFile(aContext);
trainModel(aContext, fileTrain);
copyOutcomeMappingToThisFolder(aContext);
copyFeatureNameMappingToThisFolder(aContext);
}
Aggregations