• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sentence类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:23,代码来源:StandaloneArgument.java


示例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;
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:19,代码来源:SentenceConstraintsFilter.java


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

}
 
开发者ID:UKPLab,项目名称:emnlp2017-cmapsum-corpus,代码行数:17,代码来源:TextRankScorer.java


示例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);
					}
				}
			}
		}
	}
 
开发者ID:UKPLab,项目名称:emnlp2017-cmapsum-corpus,代码行数:26,代码来源:RelationExtractorVerb.java


示例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;
}
 
开发者ID:Horsmann,项目名称:FlexTag,代码行数:18,代码来源:UseModelDKProTC.java


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

    }
}
 
开发者ID:Horsmann,项目名称:FlexTag,代码行数:27,代码来源:TcPosTaggingWrapper.java


示例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;
}
 
开发者ID:tokenmill,项目名称:dictionary-annotator,代码行数:18,代码来源:Benchmark.java


示例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++;
}
 
开发者ID:tudarmstadt-lt,项目名称:sentiment,代码行数:22,代码来源:StanfordReader.java


示例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;
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:25,代码来源:ArgumentUtils.java


示例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;
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:28,代码来源:JCasUtil2.java


示例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;
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:28,代码来源:JCasUtil2.java


示例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());
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:17,代码来源:JCasUtil2Test.java


示例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;
}
 
开发者ID:UKPLab,项目名称:jlcl2015-pythagoras,代码行数:23,代码来源:NGramUtils.java


示例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));
}
 
开发者ID:UKPLab,项目名称:jlcl2015-pythagoras,代码行数:19,代码来源:ExclamationFeatureExtractor.java


示例16: classify

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private void classify(JCas jCas, Map<Sentence, Collection<Token>> sentencesTokens,
        Map<Integer, List<Instance<String>>> sentencesInstances, List<Sentence> sentenceList,
        int index, int it, File featureFile)
            throws CleartkProcessingException
{
    List<String> namedEntities = this.classify(sentencesInstances, featureFile);
    try {
        FileUtils.copyFile(featureFile,
                new File(featureFile.getAbsolutePath() + ".test" + it * index));
    }
    catch (IOException e) {
    }
    int i = 0;
    for (Sentence s : sentenceList) {
        for (Token token : sentencesTokens.get(s)) {
            NamedEntity namedEntity = new NamedEntity(jCas, token.getBegin(), token.getEnd());
            namedEntity.setValue(namedEntities.get(i));
            namedEntity.addToIndexes();

            i++;
        }
        i++;
    }
}
 
开发者ID:tudarmstadt-lt,项目名称:GermaNER,代码行数:25,代码来源:NERAnnotator.java


示例17: writeSentence

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private void writeSentence(JCas aJCas, TextCorpus aTextCorpus,
        Map<Integer, eu.clarin.weblicht.wlfxb.tc.api.Token> aTokensBeginPositionMap)
{
    // if not TCF file, add sentence layer (Sentence is required for BRAT)
    SentencesLayer sentencesLayer = aTextCorpus.getSentencesLayer();
    if (sentencesLayer != null) {
        getLogger().debug("Layer [" + TextCorpusLayerTag.SENTENCES.getXmlName() + "]: found");
        return;
    }

    sentencesLayer = aTextCorpus.createSentencesLayer();

    getLogger().debug("Layer [" + TextCorpusLayerTag.SENTENCES.getXmlName() + "]: created");

    for (Sentence sentence : select(aJCas, Sentence.class)) {
        List<eu.clarin.weblicht.wlfxb.tc.api.Token> tokens = new ArrayList<>();
        for (Token token : selectCovered(Token.class, sentence)) {
            tokens.add(aTokensBeginPositionMap.get(token.getBegin()));
        }
        sentencesLayer.addSentence(tokens);
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:23,代码来源:TcfWriter.java


示例18: setTokenSentenceAddress

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private void setTokenSentenceAddress(JCas aJCas)
{
    int sentNMumber = 1;
    for (Sentence sentence : select(aJCas, Sentence.class)) {
        int lineNumber = 1;
        for (Token token : selectCovered(Token.class, sentence)) {
            AnnotationUnit unit = new AnnotationUnit(token.getBegin(), token.getEnd(), false,
                    token.getCoveredText());
            units.add(unit);
            if (lineNumber == 1) {
                sentenceUnits.put(unit, sentence.getCoveredText());
            }
            unitsLineNumber.put(unit, sentNMumber + "-" + lineNumber);
            lineNumber++;
        }
        sentNMumber++;
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:19,代码来源:WebannoTsv3Writer.java


示例19: createSentence

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
private void createSentence(JCas aJCas, String aLine, int aBegin, int aEnd, int aPrevEnd)
{
    // If the next sentence immediately follows the last one without any space or line break
    // in between, then we need to chop off again the linebreak that we added at the end of the
    // last sentence - otherwise offsets will be off on a round-trip.
    if (aPrevEnd == aBegin && coveredText.length() > 0
            && (coveredText.charAt(coveredText.length() - 1) == '\n')) {
        coveredText.deleteCharAt(coveredText.length() - 1);
    }

    if (aPrevEnd + 1 < aBegin) {
        // FIXME This is very slow. Better use StringUtils.repeat()
        StringBuilder pad = new StringBuilder(); // if there is plenty of spaces between
                                                 // sentences
        for (int i = aPrevEnd + 1; i < aBegin; i++) {
            pad.append(" ");
        }
        coveredText.append(pad).append(aLine).append(LF);
    }
    else {
        coveredText.append(aLine).append(LF);
    }
    Sentence sentence = new Sentence(aJCas, aBegin, aEnd);
    sentence.addToIndexes();
}
 
开发者ID:webanno,项目名称:webanno,代码行数:26,代码来源:WebannoTsv3Reader.java


示例20: test

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入依赖的package包/类
@Test
public void test()
    throws Exception
{
    JCas doc = JCasFactory.createJCas();

    CollectionReader reader = createReader(LineOrientedTextReader.class,
            LineOrientedTextReader.PARAM_SOURCE_LOCATION, "LICENSE.txt");

    reader.getNext(doc.getCas());
    
    // select(doc, Sentence.class).forEach(s -> System.out.println(s.getCoveredText()));
    
    assertEquals(169, select(doc, Sentence.class).size());
    assertEquals(0, select(doc, Token.class).size());
}
 
开发者ID:webanno,项目名称:webanno,代码行数:17,代码来源:LineOrientedTextReaderTest.java



注:本文中的de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DistributedCache类代码示例发布时间:2022-05-21
下一篇:
Java RecursiveElementNameAndTextQualifier类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap