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


Java Entity.getName方法代码示例

本文整理汇总了Java中com.google.cloud.language.v1.Entity.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getName方法的具体用法?Java Entity.getName怎么用?Java Entity.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.cloud.language.v1.Entity的用法示例。


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

示例1: processElement

import com.google.cloud.language.v1.Entity; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
	ContentIndexSummary is = c.element();

	try {

		if (this.languageClient == null)
			throw new Exception("CNLP client not initialized");
		
		com.google.cloud.language.v1.Document doc = com.google.cloud.language.v1.Document.newBuilder()
			.setContent(is.doc.text).setType(Type.PLAIN_TEXT).build();

		AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
			.setDocument(doc).setEncodingType(EncodingType.UTF16).build();

		AnalyzeEntitiesResponse response = languageClient.analyzeEntities(request);
		
		// get at most as many entities as we have tags in the Sirocco-based output
		// int entitiesToGet = Math.min(is.doc.tags.length, response.getEntitiesList().size());
		int entitiesToGet = response.getEntitiesList().size();
		DocumentTag[] newTags = new DocumentTag[entitiesToGet];
		
		// Create additional Document Tags and add them to the output index summary
		for (int idx = 0; idx < entitiesToGet; idx++) {
			// Entities are sorted by salience in the response list, so pick the first ones
			Entity entity = response.getEntitiesList().get(idx);
			DocumentTag dt = new DocumentTag();
			String tag = IndexerPipelineUtils.CNLP_TAG_PREFIX + entity.getName();
			Float weight = entity.getSalience();
			Boolean goodAsTopic = null;
			dt.initialize(tag, weight, goodAsTopic);
			newTags[idx] = dt;
		}
		
		if (entitiesToGet>0)
		{
			ContentIndexSummary iscopy = is.copy();
			DocumentTag[] combinedTags = new DocumentTag[newTags.length + iscopy.doc.tags.length];
			System.arraycopy(iscopy.doc.tags, 0, combinedTags, 0, iscopy.doc.tags.length);
			System.arraycopy(newTags, 0, combinedTags, iscopy.doc.tags.length, newTags.length);
			iscopy.doc.tags = combinedTags;
			c.output(iscopy);
		}
		else
			c.output(is);
		
	} catch (Exception e) {
		LOG.warn(e.getMessage());
	}

}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:52,代码来源:FileIndexerPipeline.java

示例2: processElement

import com.google.cloud.language.v1.Entity; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
	ContentIndexSummary is = c.element();

	try {

		if (this.languageClient == null)
			throw new Exception("CNLP client not initialized");
		
		com.google.cloud.language.v1.Document doc = com.google.cloud.language.v1.Document.newBuilder()
			.setContent(is.doc.text).setType(Type.PLAIN_TEXT).build();

		AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
			.setDocument(doc).setEncodingType(EncodingType.UTF16).build();

		AnalyzeEntitiesResponse response = languageClient.analyzeEntities(request);
		
		// get at most as many entities as we have tags in the Sirocco-based output
		int entitiesToGet = Math.min(is.doc.tags.length, response.getEntitiesList().size());
		DocumentTag[] newTags = new DocumentTag[entitiesToGet];
		
		// Create additional Document Tags and add them to the output index summary
		for (int idx = 0; idx < entitiesToGet; idx++) {
			// Entities are sorted by salience in the response list, so pick the first ones
			Entity entity = response.getEntitiesList().get(idx);
			DocumentTag dt = new DocumentTag();
			String tag = IndexerPipelineUtils.CNLP_TAG_PREFIX + entity.getName();
			Float weight = entity.getSalience();
			Boolean goodAsTopic = null;
			dt.initialize(tag, weight, goodAsTopic);
			newTags[idx] = dt;
		}
		
		if (entitiesToGet>0)
		{
			ContentIndexSummary iscopy = is.copy();
			DocumentTag[] combinedTags = new DocumentTag[newTags.length + iscopy.doc.tags.length];
			System.arraycopy(iscopy.doc.tags, 0, combinedTags, 0, iscopy.doc.tags.length);
			System.arraycopy(newTags, 0, combinedTags, iscopy.doc.tags.length, newTags.length);
			iscopy.doc.tags = combinedTags;
			c.output(iscopy);
		}
		else
			c.output(is);
		
	} catch (Exception e) {
		LOG.warn(e.getMessage());
	}

}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:51,代码来源:IndexerPipeline.java


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