-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Updates to new client library and fixes broken link in README #427
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
Changes from all commits
81d550f
4baae60
a5f7fc0
bd07872
dad9f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.api.services.language.v1.model.Entity; | ||
import com.google.cloud.language.v1.Entity; | ||
import com.google.cloud.language.v1.Entity.Builder; | ||
import com.google.cloud.language.v1.Entity.Type; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
|
@@ -67,20 +69,31 @@ public class AnalyzeTest { | |
// Arrange | ||
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
PrintStream out = new PrintStream(bout); | ||
|
||
// Mock natural-language entities based on actual data. | ||
ImmutableList<Entity> entities = | ||
ImmutableList.of( | ||
new Entity().setName("Larry Page").setSalience(0.426f).setType("PERSON").setMetadata( | ||
ImmutableMap.<String, String>builder() | ||
.put("knowledge_graph_mid", "/m/0gjpq") | ||
.put("wikipedia_url", "http://en.wikipedia.org/wiki/index.html?curid=60903") | ||
.build()), | ||
new Entity().setName("search engine").setSalience(0.188f).setType("CONSUMER_GOOD"), | ||
new Entity().setName("something")); | ||
|
||
// Act | ||
Entity.newBuilder().setName("Larry Page") | ||
.setSalience(0.426f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems really specific, should you explain it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Added verbose comments calling out this is mock data based on actual data. |
||
.setType(Type.PERSON) | ||
.putAllMetadata( | ||
ImmutableMap.<String, String>builder() | ||
.put("knowledge_graph_mid", "/m/0gjpq") | ||
.put("wikipedia_url", | ||
"http://en.wikipedia.org/wiki/index.html?curid=60903") | ||
.build()) | ||
.build(), | ||
Entity.newBuilder() | ||
.setName("search engine") | ||
.setSalience(0.188f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also seems very specific - does it deserve a comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Unless, you mean to comment on the inner members, e.g.
I'm not sure how much detail is appropriate here in the mocks. For example, AFAICT the salience of entities sums up to 1. This means that if you sorted the entities by salience, descending, the most prominent entities in the target text will appear first: the actual salience values just tell you how important this particular entity is within the scope of the document. |
||
.setType(Type.CONSUMER_GOOD) | ||
.build(), | ||
Entity.newBuilder().setName("something").build()); | ||
|
||
// Act on sample code with mock data. | ||
Analyze.printEntities(out, entities); | ||
|
||
// Assert | ||
// Assert output from sample matches expected output. | ||
String got = bout.toString(); | ||
assertThat(got).contains("Found 3 entities."); | ||
assertThat(got).contains("Larry Page"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea - Java 8. Good to see, but we don't typically use this in samples. Note - I'm Ok w/ this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. Leaving as-is.