當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。