Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NLU] Add disambiguation property #641

Merged
merged 4 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2017 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.natural_language_understanding.v1.model;

import java.util.List;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* Disambiguation information for the entity.
*/
public class DisambiguationResult extends GenericModel {

/** Common entity name. */
private String name;
@SerializedName("dbpedia_resource")
private String dbpediaResource;
/** Entity subtype information. */
private List<String> subtype;

/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}

/**
* Gets the dbpediaResource.
*
* @return the dbpediaResource
*/
public String getDbpediaResource() {
return dbpediaResource;
}

/**
* Gets the subtype.
*
* @return the subtype
*/
public List<String> getSubtype() {
return subtype;
}

/**
* Sets the name.
*
* @param name the new name
*/
public void setName(final String name) {
this.name = name;
}

/**
* Sets the dbpediaResource.
*
* @param dbpediaResource the new dbpediaResource
*/
public void setDbpediaResource(final String dbpediaResource) {
this.dbpediaResource = dbpediaResource;
}

/**
* Sets the subtype.
*
* @param subtype the new subtype
*/
public void setSubtype(final List<String> subtype) {
this.subtype = subtype;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class EntitiesResult extends GenericModel {
private Integer count;
/** The name of the entity. */
private String text;
/** Emotion analysis results for the entity, enabled with the \&quot;emotion\&quot; option. */
/** Emotion analysis results for the entity, enabled with the "emotion" option. */
private EmotionScores emotion;
/** Sentiment analysis results for the entity, enabled with the \&quot;sentiment\&quot; option. */
/** Sentiment analysis results for the entity, enabled with the "sentiment" option. */
private FeatureSentimentResults sentiment;
/** Disambiguation information for the entity. */
private DisambiguationResult disambiguation;

/**
* Gets the type.
Expand Down Expand Up @@ -86,6 +88,15 @@ public FeatureSentimentResults getSentiment() {
return sentiment;
}

/**
* Gets the disambiguation.
*
* @return the disambiguation
*/
public DisambiguationResult getDisambiguation() {
return disambiguation;
}

/**
* Sets the type.
*
Expand Down Expand Up @@ -140,4 +151,12 @@ public void setSentiment(final FeatureSentimentResults sentiment) {
this.sentiment = sentiment;
}

/**
* Sets the disambiguation.
*
* @param disambiguation the new disambiguation
*/
public void setDisambiguation(final DisambiguationResult disambiguation) {
this.disambiguation = disambiguation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,31 @@ public void analyzeTextForCategoriesIsSuccessful() throws Exception {
assertNotNull(result.getScore());
}
}

/**
* Analyze html for disambiguation.
*
* @throws Exception the exception
*/
@Test
public void analyzeHtmlForDisambiguationIsSuccessful() throws Exception {
EntitiesOptions entities = new EntitiesOptions.Builder().sentiment(true).limit(1).build();
Features features = new Features.Builder().entities(entities).build();
AnalyzeOptions parameters =
new AnalyzeOptions.Builder().url("www.cnn.com").features(features).build();

AnalysisResults results = service.analyze(parameters).execute();

assertNotNull(results);
assertEquals(results.getLanguage(), "en");
assertNotNull(results.getEntities());
assertTrue(results.getEntities().size() == 1);
for (EntitiesResult result : results.getEntities()) {
assertNotNull(result.getDisambiguation());
assertEquals(result.getDisambiguation().getName(),"CNN");
assertEquals(result.getDisambiguation().getDbpediaResource(),"http://dbpedia.org/resource/CNN");
assertNotNull(result.getDisambiguation().getSubtype());
assertTrue(result.getDisambiguation().getSubtype().size() > 0);
}
}
}