Skip to content

Commit 22c70c6

Browse files
iredpathguruxu
authored andcommitted
RD-2427 related-terms support (#142)
* RD-2427 related-terms support * RD-2427 dog -> spy for example term * RD-2427 unit test for related terms * [maven-release-plugin] prepare release rosette-api-java-binding-1.12.100 * [maven-release-plugin] prepare for next development iteration * RD-2427 support text-embeddings and semantics/vector, related terms -> similar terms * RD-2427 README points to correct examples * [maven-release-plugin] prepare release rosette-api-java-binding-1.12.101 * [maven-release-plugin] prepare for next development iteration
1 parent 6ec0e0e commit 22c70c6

File tree

21 files changed

+445
-21
lines changed

21 files changed

+445
-21
lines changed

annotations/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.basistech.rosette</groupId>
2121
<artifactId>rosette-api-java-binding</artifactId>
22-
<version>1.12.1-SNAPSHOT</version>
22+
<version>1.12.102-SNAPSHOT</version>
2323
</parent>
2424
<artifactId>rosette-api-annotations</artifactId>
2525
<name>rosette-api-annotations</name>

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.basistech.rosette</groupId>
2121
<artifactId>rosette-api-java-binding</artifactId>
22-
<version>1.12.1-SNAPSHOT</version>
22+
<version>1.12.102-SNAPSHOT</version>
2323
</parent>
2424
<artifactId>rosette-api</artifactId>
2525
<name>rosette-api</name>

api/src/test/java/com/basistech/rosette/api/RosetteAPITest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.basistech.rosette.apimodel.NameSimilarityResponse;
3131
import com.basistech.rosette.apimodel.NameTranslationRequest;
3232
import com.basistech.rosette.apimodel.NameTranslationResponse;
33+
import com.basistech.rosette.apimodel.SimilarTermsResponse;
3334
import com.basistech.rosette.apimodel.RelationshipsResponse;
3435
import com.basistech.rosette.apimodel.Request;
3536
import com.basistech.rosette.apimodel.SentimentResponse;
@@ -50,7 +51,6 @@
5051
import java.io.FileInputStream;
5152
import java.io.IOException;
5253
import java.io.InputStream;
53-
import java.net.URISyntaxException;
5454
import java.nio.charset.StandardCharsets;
5555
import java.nio.file.DirectoryStream;
5656
import java.nio.file.Files;
@@ -72,7 +72,7 @@ public RosetteAPITest(String filename) {
7272
}
7373

7474
@Parameterized.Parameters
75-
public static Collection<Object[]> data() throws URISyntaxException, IOException {
75+
public static Collection<Object[]> data() throws IOException {
7676
File dir = new File("src/test/mock-data/response");
7777
Collection<Object[]> params = new ArrayList<>();
7878
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir.toPath())) {
@@ -380,7 +380,6 @@ public void testGetSyntaxDependencies() throws IOException {
380380
}
381381
}
382382

383-
384383
private void verifySyntaxDependency(SyntaxDependenciesResponse response) throws IOException {
385384
SyntaxDependenciesResponse goldResponse = mapper.readValue(responseStr, SyntaxDependenciesResponse.class);
386385
assertEquals(response.getSentences().size(), goldResponse.getSentences().size());
@@ -400,6 +399,25 @@ public void testGetSyntaxDependenciesURL() throws IOException {
400399
}
401400
}
402401

402+
@Test
403+
public void testGetSimilarTerms() throws IOException {
404+
if (!(testFilename.endsWith("-similar_terms.json"))) {
405+
return;
406+
}
407+
DocumentRequest<?> request = readValue(DocumentRequest.class);
408+
try {
409+
SimilarTermsResponse response = api.perform(AbstractRosetteAPI.SIMILAR_TERMS_SERVICE_PATH, request, SimilarTermsResponse.class);
410+
verifySimilarTerms(response);
411+
} catch (HttpRosetteAPIException e) {
412+
verifyException(e);
413+
}
414+
}
415+
416+
private void verifySimilarTerms(SimilarTermsResponse response) throws IOException {
417+
SimilarTermsResponse goldResponse = mapper.readValue(responseStr, SimilarTermsResponse.class);
418+
assertEquals(response.getSimilarTerms().size(), goldResponse.getSimilarTerms().size());
419+
}
420+
403421
// THERE ARE NO REL FILENAMES!
404422
@Test
405423
public void testGetRelationships() throws IOException {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"content": "spy",
3+
"resultLanguages": ["spa", "deu", "jpn"],
4+
"language": "eng"
5+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"similarTerms": {
3+
"deu": [
4+
{
5+
"term": "Deckname",
6+
"similarity": 0.51391315
7+
},
8+
{
9+
"term": "GRU",
10+
"similarity": 0.50809389
11+
},
12+
{
13+
"term": "Spion",
14+
"similarity": 0.50051737
15+
},
16+
{
17+
"term": "KGB",
18+
"similarity": 0.49981388
19+
},
20+
{
21+
"term": "Informant",
22+
"similarity": 0.48774603
23+
},
24+
{
25+
"term": "Geheimagent",
26+
"similarity": 0.48700801
27+
},
28+
{
29+
"term": "Geheimdienst",
30+
"similarity": 0.48512384
31+
},
32+
{
33+
"term": "Spionin",
34+
"similarity": 0.47224587
35+
},
36+
{
37+
"term": "MI6",
38+
"similarity": 0.46969846
39+
},
40+
{
41+
"term": "Decknamen",
42+
"similarity": 0.44730526
43+
}
44+
],
45+
"jpn": [
46+
{
47+
"term": "スパイ",
48+
"similarity": 0.5544399
49+
},
50+
{
51+
"term": "諜報",
52+
"similarity": 0.46903181
53+
},
54+
{
55+
"term": "MI6",
56+
"similarity": 0.46344957
57+
},
58+
{
59+
"term": "殺し屋",
60+
"similarity": 0.41098994
61+
},
62+
{
63+
"term": "正体",
64+
"similarity": 0.40109193
65+
},
66+
{
67+
"term": "プレデター",
68+
"similarity": 0.39433435
69+
},
70+
{
71+
"term": "レンズマン",
72+
"similarity": 0.3918637
73+
},
74+
{
75+
"term": "S.H.I.E.L.D.",
76+
"similarity": 0.38338536
77+
},
78+
{
79+
"term": "サーシャ",
80+
"similarity": 0.37628397
81+
},
82+
{
83+
"term": "黒幕",
84+
"similarity": 0.37256041
85+
}
86+
],
87+
"spa": [
88+
{
89+
"term": "espía",
90+
"similarity": 0.61295485
91+
},
92+
{
93+
"term": "cia",
94+
"similarity": 0.46201307
95+
},
96+
{
97+
"term": "desertor",
98+
"similarity": 0.42849663
99+
},
100+
{
101+
"term": "cómplice",
102+
"similarity": 0.36646274
103+
},
104+
{
105+
"term": "subrepticiamente",
106+
"similarity": 0.36629659
107+
},
108+
{
109+
"term": "asesino",
110+
"similarity": 0.36264464
111+
},
112+
{
113+
"term": "misterioso",
114+
"similarity": 0.35466132
115+
},
116+
{
117+
"term": "fugitivo",
118+
"similarity": 0.35033143
119+
},
120+
{
121+
"term": "informante",
122+
"similarity": 0.34707013
123+
},
124+
{
125+
"term": "mercenario",
126+
"similarity": 0.34658083
127+
}
128+
]
129+
}
130+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
200

common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.basistech.rosette</groupId>
2121
<artifactId>rosette-api-java-binding</artifactId>
22-
<version>1.12.1-SNAPSHOT</version>
22+
<version>1.12.102-SNAPSHOT</version>
2323
</parent>
2424
<artifactId>rosette-api-common</artifactId>
2525
<name>rosette-api-common</name>

common/src/main/java/com/basistech/rosette/api/common/AbstractRosetteAPI.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public abstract class AbstractRosetteAPI implements AutoCloseable {
4545
public static final String TOKENS_SERVICE_PATH = "/tokens";
4646
public static final String SENTENCES_SERVICE_PATH = "/sentences";
4747
public static final String TEXT_EMBEDDING_SERVICE_PATH = "/text-embedding";
48+
public static final String SEMANTIC_VECTORS_SERVICE_PATH = "/semantics/vector";
49+
public static final String SIMILAR_TERMS_SERVICE_PATH = "/semantics/similar";
4850
public static final String SYNTAX_DEPENDENCIES_SERVICE_PATH = "/syntax/dependencies";
4951
public static final String TRANSLITERATION_SERVICE_PATH = "/transliteration";
5052
public static final String TOPICS_SERVICE_PATH = "/topics";
@@ -67,6 +69,8 @@ public abstract class AbstractRosetteAPI implements AutoCloseable {
6769
TOKENS_SERVICE_PATH,
6870
SENTENCES_SERVICE_PATH,
6971
TEXT_EMBEDDING_SERVICE_PATH,
72+
SEMANTIC_VECTORS_SERVICE_PATH,
73+
SIMILAR_TERMS_SERVICE_PATH,
7074
SYNTAX_DEPENDENCIES_SERVICE_PATH,
7175
TRANSLITERATION_SERVICE_PATH,
7276
TOPICS_SERVICE_PATH

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.basistech.rosette</groupId>
2222
<artifactId>rosette-api-java-binding</artifactId>
23-
<version>1.12.1-SNAPSHOT</version>
23+
<version>1.12.102-SNAPSHOT</version>
2424
</parent>
2525
<groupId>com.basistech.rosette</groupId>
2626
<artifactId>rosette-api-examples</artifactId>

examples/src/main/java/com/basistech/rosette/examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ Otherwise you can compile and run these examples by hand:
2727
| NameSimilarityExample.java | Matches two names and produces a match score
2828
| NameTranslationExample.java | Translates a name
2929
| PingExample.java | Pings the Rosette API to check for availability
30+
| SemanticVectorsExample.java | Gets the text embedding
3031
| SentencesExample.java | Gets the sentences
3132
| SentimentExample.java | Gets the sentiment of a local file
33+
| SimilarTermsExample.java | Gets the list of similar terms
3234
| SyntaxDependenciesExample.java | Gets syntactical dependencies
3335
| TokenExample.java | Gets the tokens
3436
| TopicsExample.java | Gets topics

0 commit comments

Comments
 (0)