本文整理汇总了Java中de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence类的典型用法代码示例。如果您正苦于以下问题:Java Sentence类的具体用法?Java Sentence怎么用?Java Sentence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sentence类属于de.tudarmstadt.ukp.dkpro.core.api.segmentation.type包,在下文中一共展示了Sentence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractSentences
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
public static List<HITSentence> extractSentences(StandaloneArgument argument)
throws IOException
{
// extract sentences
List<HITSentence> result = new ArrayList<>();
ArrayList<Sentence> sentences = new ArrayList<>(
JCasUtil.select(argument.getJCas(), Sentence.class));
for (int i = 0; i < sentences.size(); i++) {
Sentence sentence = sentences.get(i);
HITSentence s = new HITSentence();
// position
s.position = i;
// create unique id by combining argument id and sentence position
s.sentenceId = StandaloneArgument.getSentenceID(argument, s.position);
s.text = sentence.getCoveredText();
result.add(s);
}
return result;
}
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:26,代码来源:AbstractArgumentHITCreator.java
示例2: extractSentenceIDsAndContent
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
public static SortedMap<String, Sentence> extractSentenceIDsAndContent(
StandaloneArgument argument)
throws IOException
{
JCas jCas = argument.getJCas();
// extract sentences
SortedMap<String, Sentence> result = new TreeMap<>();
ArrayList<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));
for (int i = 0; i < sentences.size(); i++) {
Sentence sentence = sentences.get(i);
// create unique id by combining argument id and sentence position
String sentenceId = getSentenceID(argument, i);
result.put(sentenceId, sentence);
}
// System.out.println("extractSentenceIDsAndContent result keys: " + result.keySet());
return result;
}
示例3: keepArgument
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Override
public boolean keepArgument(JCas jCas)
{
List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));
// remove one-sentence arguments
if (sentences.size() == 1) {
return false;
}
for (Sentence s : sentences) {
if (s.getCoveredText().length() > MAX_SENTENCE_LENGTH) {
return false;
}
}
return true;
}
示例4: processSentence
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Override
public void processSentence(JCas jcas, Sentence sent) {
for (CC ca : JCasUtil.selectCovered(jcas, CC.class, sent)) {
Concept c = this.parent.getComponent(ConceptExtractor.class).getConcept(ca);
if (c != null) {
for (Concept cn : this.lastConcepts) {
this.pairs.add(new Pair<Concept, Concept>(cn, c));
}
this.lastConcepts.offer(c);
if (this.lastConcepts.size() > windowSize)
this.lastConcepts.poll();
}
}
}
示例5: findVerbs
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private void findVerbs(JCas jcas, Sentence sentence) {
List<CC> concepts = JCasUtil.selectCovered(jcas, CC.class, sentence);
if (concepts.size() >= 2) {
for (CC c1 : concepts) {
for (CC c2 : concepts) {
if (c1 != c2 && c1.getEnd() < c2.getBegin()) {
List<PToken> tokens = new ArrayList<PToken>();
boolean hasVerb = false;
for (Token t : JCasUtil.selectCovered(Token.class, sentence)) {
if (t.getBegin() > c1.getEnd() && t.getEnd() < c2.getBegin()) {
tokens.add(this.parent.getToken(t));
if (t.getPos().getPosValue().startsWith("V"))
hasVerb = true;
}
}
if (tokens.size() > 0 && tokens.size() < 10 && hasVerb)
this.addLink(c1, c2, tokens);
}
}
}
}
}
示例6: extractTags
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private List<List<String>> extractTags(JCas jCas)
{
List<List<String>> posTags = new ArrayList<List<String>>();
Collection<Sentence> sentences = JCasUtil.select(jCas, Sentence.class);
for (Sentence s : sentences) {
List<String> tags = new ArrayList<String>();
List<TextClassificationOutcome> tcos = JCasUtil.selectCovered(jCas,
TextClassificationOutcome.class, s.getBegin(), s.getEnd());
for (TextClassificationOutcome tco : tcos) {
tags.add(tco.getOutcome());
}
posTags.add(tags);
}
return posTags;
}
示例7: process
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Override
public void process(JCas aJCas)
throws AnalysisEngineProcessException
{
for (Sentence sent : JCasUtil.select(aJCas, Sentence.class)) {
TextClassificationSequence sequence = new TextClassificationSequence(aJCas,
sent.getBegin(), sent.getEnd());
sequence.addToIndexes();
List<Token> tokens = JCasUtil.selectCovered(aJCas, Token.class, sent);
for (Token token : tokens) {
TextClassificationTarget target = new TextClassificationTarget(aJCas, token.getBegin(),
token.getEnd());
target.setId(tcId++);
target.setSuffix(token.getCoveredText());
target.addToIndexes();
TextClassificationOutcome outcome = new TextClassificationOutcome(aJCas,
token.getBegin(), token.getEnd());
outcome.setOutcome(getTextClassificationOutcome(aJCas, target));
outcome.addToIndexes();
}
}
}
示例8: createDictionaryAnnotatorEngine
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private static AnalysisEngine createDictionaryAnnotatorEngine() throws Exception {
AggregateBuilder builder = new AggregateBuilder();
builder.add(AnalysisEngineFactory.createEngineDescription(SimpleTokenizer.class,
UimaUtil.SENTENCE_TYPE_PARAMETER, Sentence.class.getName(),
UimaUtil.TOKEN_TYPE_PARAMETER, Token.class.getName()));
builder.add(AnalysisEngineFactory.createEngineDescription(DictionaryAnnotator.class,
DictionaryAnnotator.PARAM_DICTIONARY_LOCATION, "classpath:benchmark-dictionary.csv",
DictionaryAnnotator.PARAM_TOKENIZER_CLASS, SimpleOpenNlpTokenizer.class.getName(),
DictionaryAnnotator.PARAM_ANNOTATION_TYPE, DictionaryEntry.class.getName(),
DictionaryAnnotator.PARAM_CSV_SEPARATOR, ";",
DictionaryAnnotator.PARAM_DICTIONARY_CASE_SENSITIVE, true,
DictionaryAnnotator.PARAM_DICTIONARY_ACCENT_SENSITIVE, true));
AnalysisEngine engine = AnalysisEngineFactory.createEngine(builder.createAggregateDescription());
return engine;
}
示例9: getNext
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Override
public void getNext(JCas aJcas) throws IOException, CollectionException {
File f = documents.get(i);
LineIterator it = FileUtils.lineIterator(f);
int start =0;
int inds=0;
StringBuffer sb = new StringBuffer();
while(it.hasNext()){
String line = it.nextLine();
Sentence sent = new Sentence(aJcas, start, start+line.length());
sent.addToIndexes();
start = start + line.length() + 1;
sb.append(line+"\n");
if (inds%10000==0)
System.out.println("R"+inds);
}
aJcas.setDocumentText(sb.toString());
//had to add english as default language, one could also add another configuration parameter
aJcas.setDocumentLanguage("en");
i++;
}
示例10: selectOverlappingComponentsWithoutPathosAndImplicit
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
/**
* Select argument components that are present in this sentence (by calling
* {@code JCasUtil2#selectOverlapping()} and filters the results so that pathos dimension
* and implicit components are ignored.
*
* @param sentence sentence
* @param jCas jcas
* @return list of argument components
*/
public static List<ArgumentComponent> selectOverlappingComponentsWithoutPathosAndImplicit(
Sentence sentence, JCas jCas)
{
List<ArgumentComponent> result = JCasUtil2
.selectOverlapping(ArgumentComponent.class, sentence, jCas);
// remove appeal to emotion
result = ArgumentUtils.removeAppealToEmotion(result);
// remove implicit arguments (if there are any remaining)
result = ArgumentUtils.removeImplicitComponents(result);
return result;
}
示例11: getPrecedingSentences
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
/**
* Returns a list of annotations of the same type preceding the given annotation
*
* @param jCas jcas
* @param annotation sentence
* @return list of sentences sorted incrementally by position
*/
public static List<Sentence> getPrecedingSentences(JCas jCas, Sentence annotation)
{
List<Sentence> result = new ArrayList<Sentence>();
for (Sentence sentence : JCasUtil.select(getInitialView(jCas), Sentence.class)) {
if (sentence.getBegin() < annotation.getBegin()) {
result.add(sentence);
}
}
Collections.sort(result, new Comparator<Sentence>()
{
@Override public int compare(Sentence o1, Sentence o2)
{
return o2.getBegin() - o1.getBegin();
}
});
return result;
}
示例12: getSucceedingSentences
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
/**
* Returns a list of annotations of the same type succeeding the given annotation
*
* @param jCas jcas
* @param annotation sentence
* @return list of sentences sorted incrementally by position
*/
public static List<Sentence> getSucceedingSentences(JCas jCas, Sentence annotation)
{
List<Sentence> result = new ArrayList<Sentence>();
for (Sentence sentence : JCasUtil.select(getInitialView(jCas), Sentence.class)) {
if (sentence.getBegin() > annotation.getBegin()) {
result.add(sentence);
}
}
Collections.sort(result, new Comparator<Sentence>()
{
@Override public int compare(Sentence o1, Sentence o2)
{
return o2.getBegin() - o1.getBegin();
}
});
return result;
}
示例13: testSelectImplicitComponent
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Test
public void testSelectImplicitComponent()
throws Exception
{
Sentence s1 = new Sentence(jCas);
s1.setBegin(this.tokenThis.getBegin());
s1.setEnd(this.tokenIs.getEnd());
s1.addToIndexes();
Sentence s = new ArrayList<Sentence>(JCasUtil.select(jCas, Sentence.class)).get(0);
// it ignore implicit (zero-length) component -- here at [0, 0], sentence starts at 0
ArgumentComponent implicitComponent = new ArgumentComponent(jCas, 0, 0);
implicitComponent.addToIndexes();
assertEquals(0, JCasUtil2.selectOverlapping(ArgumentComponent.class, s, jCas).size());
}
示例14: getDocumentPosNgrams
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
public static FrequencyDistribution<String> getDocumentPosNgrams(JCas jcas, int minN, int maxN, boolean useCanonical)
{
FrequencyDistribution<String> posNgrams = new FrequencyDistribution<String>();
for (Sentence s : select(jcas, Sentence.class)) {
List<String> postagstrings = new ArrayList<String>();
for (POS p : JCasUtil.selectCovered(jcas, POS.class, s)) {
if (useCanonical) {
postagstrings.add(p.getClass().getSimpleName());
}
else {
postagstrings.add(p.getPosValue());
}
}
String[] posarray = postagstrings.toArray(new String[postagstrings.size()]);
for (List<String> ngram : new NGramStringListIterable(posarray, minN, maxN)) {
posNgrams.inc(StringUtils.join(ngram, NGRAM_GLUE));
}
}
return posNgrams;
}
示例15: extract
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Override
public List<Feature> extract(JCas jcas)
throws TextClassificationException
{
double sentences = JCasUtil.select(jcas, Sentence.class).size();
String text = jcas.getDocumentText();
Pattern p = Pattern.compile("\\!+");
int matches = 0;
Matcher m = p.matcher(text);
while (m.find()) {
matches++;
}
return Arrays.asList(new Feature(FEATURE_NAME, sentences > 0 ? (matches / sentences) : 0));
}