Java tutorial
/* * Copyright 2013 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.lt.n2n.preparsed.annotators; import org.apache.commons.lang.StringUtils; import org.apache.uima.analysis_engine.AnalysisEngineProcessException; import org.apache.uima.fit.component.JCasAnnotator_ImplBase; import org.apache.uima.fit.descriptor.ConfigurationParameter; import org.apache.uima.jcas.JCas; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData; /** * * @author Steffen Remus */ public class PreParsedLineAnnotator extends JCasAnnotator_ImplBase { private final static Logger LOG = LoggerFactory.getLogger(PreParsedLineAnnotator.class); public static final String PARAM_CREATE_SENTENCE_ANNOTATIONS = "_create_sentences"; @ConfigurationParameter(name = PARAM_CREATE_SENTENCE_ANNOTATIONS, mandatory = true, defaultValue = { "true" }) private boolean _create_sentences; public static final String PARAM_CREATE_TOKEN_ANNOTATIONS = "_create_tokens"; @ConfigurationParameter(name = PARAM_CREATE_TOKEN_ANNOTATIONS, mandatory = true, defaultValue = { "true" }) private boolean _create_tokens; public static final String PARAM_CREATE_DEPENDENCY_ANNOTATIONS = "_create_dependencies"; @ConfigurationParameter(name = PARAM_CREATE_DEPENDENCY_ANNOTATIONS, mandatory = true, defaultValue = { "true" }) private boolean _create_dependencies; public static final String PARAM_CREATE_COLLAPSED_DEPENDENCY_ANNOTATIONS = "_create_collapsed_dependencies"; @ConfigurationParameter(name = PARAM_CREATE_COLLAPSED_DEPENDENCY_ANNOTATIONS, mandatory = true, defaultValue = { "true" }) private boolean _create_collapsed_dependencies; public static final String PARAM_CREATE_CONSTITUENTS_ANNOTATIONS = "_create_constituents"; @ConfigurationParameter(name = PARAM_CREATE_CONSTITUENTS_ANNOTATIONS, mandatory = true, defaultValue = { "true" }) private boolean _create_constituents; public static final String PARAM_WRITE_PENNTREE_STRING = "_write_penntree"; @ConfigurationParameter(name = PARAM_WRITE_PENNTREE_STRING, defaultValue = { "false" }) private boolean _write_penntree; public static final String PARAM_FAIL_EARLY = "_fail_early"; @ConfigurationParameter(name = PARAM_FAIL_EARLY, mandatory = false, defaultValue = { "false" }) private boolean _fail_early; private PreParsedLineParser _parser = new PreParsedLineParser(); @Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try { _parser.parse(aJCas, _create_sentences, _create_tokens, _create_dependencies, _create_collapsed_dependencies, _create_constituents, _write_penntree); } catch (Exception e) { LOG.warn("Could not process cas {}, text: '{}' ({}: {})", DocumentMetaData.get(aJCas).getDocumentId(), StringUtils.abbreviate(aJCas.getDocumentText(), 50), e.getClass().getSimpleName(), e.getMessage()); if (_fail_early) throw new AnalysisEngineProcessException(e); } } }