当前位置: 首页>>代码示例>>Java>>正文


Java JCasUtil.exists方法代码示例

本文整理汇总了Java中org.apache.uima.fit.util.JCasUtil.exists方法的典型用法代码示例。如果您正苦于以下问题:Java JCasUtil.exists方法的具体用法?Java JCasUtil.exists怎么用?Java JCasUtil.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.uima.fit.util.JCasUtil的用法示例。


在下文中一共展示了JCasUtil.exists方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {

	SortedSet<Annotation> anchors = new TreeSet<Annotation>(new AnnotationComparator());
	anchors.addAll(JCasUtil.select(jcas, Utterance.class));
	anchors.addAll(JCasUtil.select(jcas, Scene.class));
	anchors.addAll(JCasUtil.select(jcas, Act.class));
	anchors.addAll(JCasUtil.select(jcas, StageDirection.class));

	if (anchors.isEmpty())
		return;

	// Acts
	if (!JCasUtil.exists(jcas, Act.class)) {
		AnnotationFactory.createAnnotation(jcas, anchors.first().getBegin(), anchors.last().getEnd(), Act.class)
				.setRegular(false);
	}

	// Scenes
	if (!JCasUtil.exists(jcas, Scene.class)) {
		for (Act act : JCasUtil.select(jcas, Act.class)) {
			AnnotationFactory.createAnnotation(jcas, act.getBegin(), act.getEnd(), Scene.class).setRegular(false);
		}
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:26,代码来源:SceneActAnnotator.java

示例2: readActs

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static void readActs(JCas jcas, Element root, Map<String, HTMLAnnotation> map, boolean strict) {
	if (!root.select("div[type=act]").isEmpty()) {
		for (Act a : select2Annotation(jcas, root, map, "div[type=act]", Act.class, null)) {
			a.setRegular(true);
		}

		select2Annotation(jcas, root, map, "div[type=act] > div > desc > title", ActHeading.class, null);
		select2Annotation(jcas, root, map, "div[type=act] > div > head", ActHeading.class, null);

		for (Act prol : select2Annotation(jcas, root, map, "div[type=prologue]", Act.class, null)) {
			prol.setRegular(false);
		}

	}
	if (!strict && !JCasUtil.exists(jcas, Act.class)) {
		select2Annotation(jcas, root, map, "body > div", Act.class, null);
		select2Annotation(jcas, root, map, "body > div > head", ActHeading.class, null);
		select2Annotation(jcas, root, map, "body > div > desc > title", ActHeading.class, null);
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:21,代码来源:TextGridUtil.java

示例3: readScenes

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
/**
 * Detect scenes. The following things are checked:
 * <ol>
 * <li>if they are explicitly marked with <code>type=scnee</code>, we take
 * them and return.</li>
 * <li>if Act annotations do exist in the JCas, we search for divs that have
 * head annotations.</li>
 * </ol>
 * 
 * @param jcas
 * @param root
 * @param map
 */
public static void readScenes(JCas jcas, Element root, Map<String, HTMLAnnotation> map, boolean strict) {
	if (!root.select("div[type=scene]").isEmpty()) {
		select2Annotation(jcas, root, map, "div[type=scene]", Scene.class, null);
		select2Annotation(jcas, root, map, "div[type=scene] > div > desc > title", SceneHeading.class, null);

		for (Scene scene : JCasUtil.select(jcas, Scene.class))
			scene.setRegular(true);
	} else if (!strict) {
		if (JCasUtil.exists(jcas, Act.class))
			for (Act act : JCasUtil.select(jcas, Act.class)) {

				Collection<Scene> scenes = select2Annotation(jcas, root, map, "body > div > div:has(head)",
						Scene.class, act);
				for (Scene sc : scenes) {
					select2Annotation(jcas, root, map, "div > desc > title", SceneHeading.class, sc);
				}
			}
		else {
			select2Annotation(jcas, root, map, "body > div > div:not(:has(desc > title))", Scene.class, null);
			select2Annotation(jcas, root, map, "body > div > div > head", SceneHeading.class, null);
			select2Annotation(jcas, root, map, "body > div > div > desc > title", SceneHeading.class, null);
		}
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:38,代码来源:TextGridUtil.java

示例4: checkSanity

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
private void checkSanity(JCas jcas) {
	assertTrue(Drama.get(jcas).getDocumentId(), JCasUtil.exists(jcas, Drama.class));
	assertTrue(Drama.get(jcas).getDocumentId(), JCasUtil.exists(jcas, Speaker.class));

	if (JCasUtil.exists(jcas, ActHeading.class)) {
		for (Act act : JCasUtil.select(jcas, Act.class)) {
			assertEquals(Drama.get(jcas).getDocumentId(), 1, JCasUtil.selectCovered(ActHeading.class, act).size());
		}
	}
	// check that speaker annotations are not empty
	for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
		assertNotEquals(Drama.get(jcas).getDocumentId(), speaker.getBegin(), speaker.getEnd());
	}

	// check that figure annotations are not empty
	for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
		assertNotEquals(figure.getBegin(), figure.getEnd());
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:20,代码来源:TestTextgridTEIFileReader.java

示例5: testGeneral

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Test
public void testGeneral() {
	assertEquals("v3mx.0", JCasUtil.selectSingle(jcas, Drama.class).getDocumentId());

	assertTrue(JCasUtil.exists(jcas, Drama.class));
	assertTrue(JCasUtil.exists(jcas, Figure.class));
	assertTrue(JCasUtil.exists(jcas, Act.class));
	assertTrue(JCasUtil.exists(jcas, Scene.class));
	assertTrue(JCasUtil.exists(jcas, Speaker.class));
	assertTrue(JCasUtil.exists(jcas, DramatisPersonae.class));
	assertTrue(JCasUtil.exists(jcas, Author.class));

	if (JCasUtil.exists(jcas, ActHeading.class)) {
		for (Act act : JCasUtil.select(jcas, Act.class)) {
			assertEquals(1, JCasUtil.selectCovered(ActHeading.class, act).size());
		}
	}
	// check that speaker annotations are not empty
	for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
		assertNotEquals(speaker.getBegin(), speaker.getEnd());
	}

	assertNotNull(JCasUtil.selectSingle(jcas, FrontMatter.class));
	assertNotNull(JCasUtil.selectSingle(jcas, MainMatter.class));

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:27,代码来源:TestGDCReaderV3mx0.java

示例6: checkSanity

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static void checkSanity(JCas jcas) {
	assertTrue(JCasUtil.exists(jcas, Drama.class));
	assertTrue(JCasUtil.exists(jcas, Figure.class));
	assertTrue(JCasUtil.exists(jcas, Act.class));
	assertTrue(JCasUtil.exists(jcas, Scene.class));
	assertTrue(JCasUtil.exists(jcas, Speaker.class));
	assertTrue(JCasUtil.exists(jcas, DramatisPersonae.class));
	assertTrue(JCasUtil.exists(jcas, Author.class));

	if (JCasUtil.exists(jcas, ActHeading.class)) {
		for (Act act : JCasUtil.select(jcas, Act.class)) {
			assertEquals(1, JCasUtil.selectCovered(ActHeading.class, act).size());
		}
	}
	// check that speaker annotations are not empty
	for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
		assertNotEquals(speaker.getBegin(), speaker.getEnd());
	}

	// check that figure annotations are not empty
	for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
		assertNotEquals(figure.getBegin(), figure.getEnd());
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:25,代码来源:TestGenerics.java

示例7: process

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
	Drama drama = JCasUtil.selectSingle(jcas, Drama.class);

	Author author = new Author(jcas);
	author.addToIndexes();
	if (authorName != null)
		author.setName(authorName);
	if (authorPnd != null)
		author.setPnd(authorPnd);
	if (dramaId != null)
		drama.setDocumentId(dramaId);
	if (referenceDate > 0)
		DramaUtil.createFeatureStructure(jcas, DateReference.class).setYear(referenceDate);
	if (dramaTitle != null)
		drama.setDocumentTitle(dramaTitle);

	drama.setTranslation(translation);
	if (translation) {
		Translator translator;
		if (JCasUtil.exists(jcas, Translator.class)) {
			translator = JCasUtil.selectSingle(jcas, Translator.class);
		} else {
			translator = DramaUtil.createFeatureStructure(jcas, Translator.class);
		}
		if (translatorName != null)
			translator.setName(translatorName);
		if (translatorPnd != null)
			translator.setPnd(translatorPnd);
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:32,代码来源:SetDramaMetaData.java

示例8: testGeneral

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Test
public void testGeneral() {
	assertEquals("ndtw.0", JCasUtil.selectSingle(jcas, Drama.class).getDocumentId());

	assertTrue(JCasUtil.exists(jcas, Drama.class));
	assertFalse(JCasUtil.exists(jcas, Figure.class));
	assertTrue(JCasUtil.exists(jcas, Act.class));
	assertTrue(JCasUtil.exists(jcas, Scene.class));
	assertTrue(JCasUtil.exists(jcas, Speaker.class));
	// no dramatis personae in ndtw.0
	assertFalse(JCasUtil.exists(jcas, DramatisPersonae.class));
	assertTrue(JCasUtil.exists(jcas, Author.class));

	if (JCasUtil.exists(jcas, ActHeading.class)) {
		for (Act act : JCasUtil.select(jcas, Act.class)) {
			assertEquals(1, JCasUtil.selectCovered(ActHeading.class, act).size());
		}
	}
	// check that speaker annotations are not empty
	for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
		assertNotEquals(speaker.getBegin(), speaker.getEnd());
	}

	assertNotNull(JCasUtil.selectSingle(jcas, FrontMatter.class));
	assertNotNull(JCasUtil.selectSingle(jcas, MainMatter.class));

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:28,代码来源:TestGDCReaderNdtw0.java

示例9: main

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InvalidXMLException,
        ResourceInitializationException, AnalysisEngineProcessException, CASException,
        SAXException {
  if (args.length != 2) {
    System.err.println("Usage: XmiToOpenNlpTrainer <input folder with xmis> <output file>");
  }

  AnalysisEngineDescription descriptor = (AnalysisEngineDescription) createResourceCreationSpecifier(
          new XMLInputSource(XmiToOpenNlpTrainer.class.getClassLoader().getResourceAsStream(
                  "org/ie4opendata/octroy/SimpleFrenchTokenAndSentenceAnnotator.xml"), new File(
                  ".")), new Object[0]);
  AnalysisEngine engine = AnalysisEngineFactory.createEngine(descriptor);
  CAS cas = engine.newCAS();

  PrintWriter pw = new PrintWriter(new FileWriter(args[1]));

  for (File file : new File(args[0]).listFiles()) {
    cas.reset();

    InputStream is = new FileInputStream(file);
    XmiCasDeserializer.deserialize(is, cas, true);

    JCas jcas = cas.getJCas();

    if (!JCasUtil.exists(jcas, DocumentAnnotation.class)) {
      DocumentAnnotation documentAnnotation = new DocumentAnnotation(cas.getJCas());
      documentAnnotation.setDocumentName(file.getName());
      documentAnnotation.setClassified(false);
      documentAnnotation.addToIndexes();
    }

    if (!JCasUtil.exists(jcas, Sentence.class))
      engine.process(cas);

    List<int[]> companyBoundaries = new ArrayList<int[]>();
    for (Company company : JCasUtil.select(jcas, Company.class))
      companyBoundaries.add(new int[] { company.getBegin(), company.getEnd() });

    int currentCompany = 0;
    boolean inCompany = false;

    // one sentence per line, one token separated by spaces
    for (Sentence sentence : JCasUtil.select(jcas, Sentence.class)) {
      if (inCompany) {
        if (sentence.getBegin() >= companyBoundaries.get(currentCompany)[1]) {
          inCompany = false;
          currentCompany++;
        } else
          pw.print(" <START:company> ");
      }

      for (Token token : JCasUtil.selectCovered(Token.class, sentence)) {
        if (currentCompany < companyBoundaries.size()) {
          if (inCompany) {
            if (token.getBegin() >= companyBoundaries.get(currentCompany)[1]) {
              pw.println(" <END> ");
              inCompany = false;
              currentCompany++;
            }
          } else {
            if (token.getBegin() >= companyBoundaries.get(currentCompany)[0]) {
              pw.print(" <START:company> ");
              inCompany = true;
            }
          }
        }
        pw.print(token.getCoveredText() + " ");
      }
      if (inCompany) {
        pw.println(" <END> ");
      }
      pw.println();
    }
    // each document separated by an empty line
    pw.println();
  }
  pw.close();
}
 
开发者ID:IE4OpenData,项目名称:Octroy,代码行数:79,代码来源:XmiToOpenNlpTrainer.java

示例10: getGraph

import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static Graph<Figure, DefaultWeightedEdge> getGraph(JCas jcas, String viewName)
		throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException,
		InvocationTargetException, NoSuchMethodException, SecurityException, CASException {

	JCas graphView = jcas.getView(viewName);

	Map<Integer, Figure> figureMap = new HashMap<Integer, Figure>();
	for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
		figureMap.put(figure.getBegin(), figure);
	}
	if (!JCasUtil.exists(graphView, GraphMetaData.class))
		return null;
	GraphMetaData gmd = JCasUtil.selectSingle(graphView, GraphMetaData.class);

	Class<?> cl = Class.forName(gmd.getGraphClassName());
	@SuppressWarnings("unchecked")
	Graph<Figure, DefaultWeightedEdge> graph = (Graph<Figure, DefaultWeightedEdge>) cl.getConstructor(Class.class)
			.newInstance(DefaultWeightedEdge.class);
	boolean weighted = false;
	if (graph instanceof WeightedGraph) {
		weighted = true;
	}

	// SimpleWeightedGraph<Figure, DefaultWeightedEdge> graph =
	// new SimpleWeightedGraph<Figure, DefaultWeightedEdge>(
	// DefaultWeightedEdge.class);
	Pattern pattern;
	if (weighted)
		pattern = Pattern.compile("(-?\\d+) (-?\\d+) (\\d+.\\d+)");
	else
		pattern = Pattern.compile("(-?\\d+) (-?\\d+)");
	for (String line : graphView.getDocumentText().split("\n")) {
		Matcher m = pattern.matcher(line);
		if (m.find()) {
			int sId = Integer.valueOf(m.group(1));
			int tId = Integer.valueOf(m.group(2));

			Figure sFigure = figureMap.get(sId);
			Figure tFigure = figureMap.get(tId);
			if (!graph.containsVertex(sFigure))
				graph.addVertex(sFigure);
			if (!graph.containsVertex(tFigure))
				graph.addVertex(tFigure);
			Object edge = graph.addEdge(sFigure, tFigure);
			if (weighted) {
				double w = Double.valueOf(m.group(3));
				if (edge != null)
					((WeightedGraph<Figure, DefaultWeightedEdge>) graph).setEdgeWeight((DefaultWeightedEdge) edge,
							w);
			}
		}
	}

	return graph;

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:57,代码来源:GraphImporter.java


注:本文中的org.apache.uima.fit.util.JCasUtil.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。