Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit e7229bf

Browse files
Merge branch 'master' into JoelGardes-patch-1
2 parents 556005a + e968976 commit e7229bf

File tree

204 files changed

+3904
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+3904
-129
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ VERSION=`git describe`
44
build-notest:
55
(cd simdoc/core/java/ && mvn -Dmaven.repo.local=${HOME}/.m2/repository install -DskipTests=true)
66
(cd simdoc/apps && mvn -Dmaven.repo.local=${HOME}/.m2/repository install -DskipTests=true)
7-
(cd simdoc/simdoc-server/ && mvn -Dmaven.repo.local=${HOME}/.m2/repository install -DskipTests=true)
7+
(cd simdoc/clustering-server/ && mvn -Dmaven.repo.local=${HOME}/.m2/repository install -DskipTests=true)
88

99
build-tests:
1010
(cd simdoc/core/java/ && mvn -Dmaven.repo.local=${HOME}/.m2/repository install)
1111
(cd simdoc/apps && mvn -Dmaven.repo.local=${HOME}/.m2/repository install)
12-
(cd simdoc/simdoc-server/ && mvn -Dmaven.repo.local=${HOME}/.m2/repository install)
12+
(cd simdoc/clustering-server/ && mvn -Dmaven.repo.local=${HOME}/.m2/repository install)
1313

1414
# Used to build debian package
1515
# here we consider that artifacts are already built (to speed up continuous integration)
@@ -27,7 +27,7 @@ deb:
2727
# Debian package install
2828
install:
2929
rm -rf usr && mkdir -p usr/share/java
30-
cp simdoc/simdoc-server/target/simdoc-server-*.jar usr/share/java/simdoc-server.jar
30+
cp simdoc/clustering-server/target/clustering-server-*.jar usr/share/java/clustering-server.jar
3131
rm -rf etc && mkdir -p etc/init.d && cp debian/server-init-d etc/init.d/simdoc-server
3232
mkdir etc/rc2.d && (cd etc/rc2.d && ln -s ../init.d/simdoc-server S08simdoc-server)
3333

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![License](https://img.shields.io/aur/license/yaourt.svg?maxAge=2592000)](https://github.com/Orange-OpenSource/documentare-simdoc/blob/master/LICENSE)
33

44
# Documentare, SimDoc library & tools
5-
Library and tools for similarity measurement, classification and clustering of digital content and segmentation images from digitized document
5+
Library and tools for similarity measurement, classification and clustering of digital content and segmentation images from digitized document.
66

77
## Build
88

simdoc/apps/clustering-remote/src/main/java/com/orange/documentare/app/clusteringremote/ClusteringRemoteApp.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
import org.apache.commons.cli.ParseException;
1515

1616
import java.io.IOException;
17+
import java.util.Currency;
1718

1819
@Slf4j
1920
public class ClusteringRemoteApp {
2021

21-
private static ClusteringRequest clusteringRequest;
22+
private static ClusteringRequest remoteClusteringRequest;
2223

2324
public static void main(String[] args) throws IllegalAccessException, IOException, ParseException {
2425
System.out.println("\n[ClusteringRemote - Start]");
2526
try {
26-
clusteringRequest = (new CommandLineOptions(args)).clusteringRequest();
27+
remoteClusteringRequest = (new CommandLineOptions(args)).clusteringRequest();
2728
} catch (Exception e) {
2829
CommandLineOptions.showHelp(e);
2930
return;
@@ -37,8 +38,49 @@ public static void main(String[] args) throws IllegalAccessException, IOExceptio
3738
}
3839

3940
private static void doTheJob() throws IOException {
40-
System.out.println("Clustering parameters, " + clusteringRequest);
41+
System.out.println("Clustering parameters, " + remoteClusteringRequest);
4142
RemoteClustering remoteClustering = new RemoteClustering();
42-
remoteClustering.request("http://localhost:8080", clusteringRequest);
43+
String url = remoteClusteringRequest.url;
44+
ClusteringRequest clusteringRequest = buildClusteringRequest();
45+
46+
remoteClustering.request(url, clusteringRequest);
47+
}
48+
49+
private static ClusteringRequest buildClusteringRequest() {
50+
ClusteringRequest.ClusteringRequestBuilder clusteringRequestBuilder = ClusteringRequest.builder()
51+
.bytesData(remoteClusteringRequest.bytesData)
52+
.outputDirectory(remoteClusteringRequest.outputDirectory);
53+
54+
if (remoteClusteringRequest.acutSdFactor != null) {
55+
clusteringRequestBuilder.acut(remoteClusteringRequest.acutSdFactor);
56+
}
57+
58+
if (remoteClusteringRequest.ccutPercentile != null) {
59+
clusteringRequestBuilder.ccut(remoteClusteringRequest.ccutPercentile);
60+
}
61+
62+
if (remoteClusteringRequest.qcutSdFactor != null) {
63+
clusteringRequestBuilder.qcut(remoteClusteringRequest.qcutSdFactor);
64+
}
65+
66+
if (remoteClusteringRequest.scutSdFactor != null) {
67+
clusteringRequestBuilder.scut(remoteClusteringRequest.scutSdFactor);
68+
}
69+
70+
71+
if ((remoteClusteringRequest.wcut != null) && (remoteClusteringRequest.wcut == true)) {
72+
clusteringRequestBuilder.wcut();
73+
}
74+
75+
if ((remoteClusteringRequest.debug != null) && (remoteClusteringRequest.debug == true)) {
76+
clusteringRequestBuilder.debug();
77+
}
78+
79+
if ((remoteClusteringRequest.sloop != null) && (remoteClusteringRequest.sloop == true)) {
80+
clusteringRequestBuilder.sloop();
81+
}
82+
83+
return clusteringRequestBuilder
84+
.build();
4385
}
4486
}

simdoc/apps/clustering-remote/src/main/java/com/orange/documentare/app/clusteringremote/ClusteringRequest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
import lombok.RequiredArgsConstructor;
1616
import lombok.ToString;
1717

18+
import java.io.File;
19+
1820
@ToString
1921
@EqualsAndHashCode
2022
@RequiredArgsConstructor
2123
public class ClusteringRequest {
24+
public final String url;
2225
public final String inputDirectory;
2326
public final BytesData[] bytesData;
2427
public final String outputDirectory;
@@ -36,6 +39,7 @@ public static ClusteringRequestBuilder builder() {
3639
}
3740

3841
public static class ClusteringRequestBuilder {
42+
public String url;
3943
private String inputDirectory;
4044
private BytesData[] bytesData;
4145
private String outputDirectory;
@@ -52,12 +56,17 @@ private ClusteringRequestBuilder() {
5256
}
5357

5458
public ClusteringRequest build() {
55-
return new ClusteringRequest(inputDirectory, bytesData, outputDirectory, debug, acutSdFactor, qcutSdFactor, scutSdFactor, ccutPercentile, wcut, kNearestNeighboursThreshold, sloop);
59+
return new ClusteringRequest(url, inputDirectory, bytesData, outputDirectory, debug, acutSdFactor, qcutSdFactor, scutSdFactor, ccutPercentile, wcut, kNearestNeighboursThreshold, sloop);
5660
}
5761

62+
public ClusteringRequestBuilder url(String url) {
63+
this.url = url;
64+
return this;
65+
}
5866

5967
public ClusteringRequestBuilder inputDirectory(String inputDirectory) {
60-
this.inputDirectory = inputDirectory;
68+
BytesData[] bytesData = BytesData.loadFromDirectory(new File(inputDirectory), File::getName);
69+
this.bytesData(bytesData);
6170
return this;
6271
}
6372

simdoc/apps/clustering-remote/src/main/java/com/orange/documentare/app/clusteringremote/cmdline/CommandLineOptions.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static com.orange.documentare.core.comp.clustering.graph.ClusteringParameters.*;
2323

2424
public class CommandLineOptions {
25+
private static final String URL_REMOTE_SERVER = "url";
2526
private static final String HELP = "h";
2627
private static final String INPUT_DIRECTORY = "din";
2728
private static final String OUTPUT_DIRECTORY = "dout";
@@ -58,12 +59,13 @@ private void init(String[] args) throws ParseException, IOException {
5859
}
5960

6061
private void initOptions(CommandLine commandLine) throws IOException {
62+
boolean dUrlOption = commandLine.hasOption(URL_REMOTE_SERVER);
6163
boolean dInOption = commandLine.hasOption(INPUT_DIRECTORY);
6264
boolean dOutOption = commandLine.hasOption(OUTPUT_DIRECTORY);
6365
boolean bytesDataOption = commandLine.hasOption(BYTE_DATA_JSON);
6466

65-
if (!dInOption && !bytesDataOption && !dOutOption) {
66-
throw new CommandLineException("input directory or bytes data json or output directory argument is missing\n");
67+
if (!dUrlOption && !dInOption && !bytesDataOption && !dOutOption) {
68+
throw new CommandLineException("remote server url or input directory or bytes data json or output directory argument is missing\n");
6769
} else {
6870
if (commandLine.hasOption(ACUT)) {
6971
builder.acut(Float.parseFloat(commandLine.getOptionValue(ACUT, String.valueOf(A_DEFAULT_SD_FACTOR))));
@@ -87,6 +89,10 @@ private void initOptions(CommandLine commandLine) throws IOException {
8789
builder.kNearestNeighboursThreshold(Integer.parseInt(commandLine.getOptionValue(KNN)));
8890
}
8991

92+
if (dUrlOption) {
93+
builder.url(commandLine.getOptionValue(URL_REMOTE_SERVER));
94+
}
95+
9096
if (dInOption) {
9197
builder.inputDirectory(commandLine.getOptionValue(INPUT_DIRECTORY));
9298
}
@@ -110,6 +116,7 @@ private BytesData[] loadBytesDataJson(String filePath) throws IOException {
110116
}
111117

112118
private CommandLine getCommandLineFromArgs(String[] args) throws ParseException {
119+
Option url = OptionBuilder.withArgName("url for remote server").hasArg().withDescription("url for remote server").create(URL_REMOTE_SERVER);
113120
Option help = new Option(HELP, "print this message");
114121

115122
Option din = OptionBuilder.withArgName("input directory").hasArg().withDescription("input directory").create(INPUT_DIRECTORY);
@@ -151,6 +158,7 @@ private CommandLine getCommandLineFromArgs(String[] args) throws ParseException
151158
.desc("kNearestNeighboursThreshold")
152159
.build();
153160

161+
options.addOption(url);
154162
options.addOption(help);
155163
options.addOption(din);
156164
options.addOption(bytesDataJson);

simdoc/apps/clustering-remote/src/test/java/com/orange/documentare/app/clusteringremote/RemoteClusteringTest.java

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void cleanup() {
4141
}
4242

4343
@Test
44-
@Ignore // a running simdoc-server is mandatory for this test
44+
@Ignore // a running clustering-server on port 6969 is mandatory for this test
4545
public void remote_build_animals_dna_clustering() throws IOException {
4646
// Given
4747
ClusteringRequest req = ClusteringRequest.builder()
@@ -53,14 +53,14 @@ public void remote_build_animals_dna_clustering() throws IOException {
5353
RemoteClustering remoteClustering = new RemoteClustering();
5454

5555
// When
56-
ClusteringRequestResult result = remoteClustering.request("http://localhost:8080", req);
56+
ClusteringRequestResult result = remoteClustering.request("http://localhost:6969", req);
5757

5858
// Then
59-
Assertions.assertThat(result).isEqualTo(expectedClusteringResult(false));
59+
Assertions.assertThat(result).isEqualTo(expectedClusteringResult());
6060
}
6161

6262
@Test
63-
@Ignore // a running simdoc-server is mandatory for this test
63+
@Ignore // a running clustering-server on port 6969 is mandatory for this test
6464
public void remote_build_animals_dna_clustering_with_bytes_data() throws IOException {
6565
// Given
6666
ClusteringRequest req = ClusteringRequest.builder()
@@ -71,11 +71,51 @@ public void remote_build_animals_dna_clustering_with_bytes_data() throws IOExcep
7171

7272
RemoteClustering remoteClustering = new RemoteClustering();
7373

74+
// When
75+
ClusteringRequestResult result = remoteClustering.request("http://localhost:6969", req);
76+
77+
// Then
78+
ClusteringRequestResult expected = expectedClusteringResult();
79+
Assertions.assertThat(result).isEqualTo(expected);
80+
}
81+
82+
83+
@Test
84+
@Ignore // a running mediation-server on port 8080 and clustering-server on port 6969 is mandatory for this test
85+
public void remote_build_animals_dna_clustering_with_mediation() throws IOException {
86+
// Given
87+
ClusteringRequest req = ClusteringRequest.builder()
88+
.inputDirectory(inputDirectory())
89+
.outputDirectory(OUTPUT_DIRECTORY.getAbsolutePath())
90+
.debug()
91+
.build();
92+
93+
RemoteClustering remoteClustering = new RemoteClustering();
94+
7495
// When
7596
ClusteringRequestResult result = remoteClustering.request("http://localhost:8080", req);
7697

7798
// Then
78-
ClusteringRequestResult expected = expectedClusteringResult(true);
99+
Assertions.assertThat(result).isEqualTo(expectedClusteringResultWithMediation());
100+
}
101+
102+
@Test
103+
@Ignore // a running mediation-server on port 8080 and clustering-server on port 6969 is mandatory for this test
104+
public void remote_build_animals_dna_clustering_with_bytes_data_with_mediation() throws IOException {
105+
// Given
106+
ClusteringRequest req = ClusteringRequest.builder()
107+
.bytesData(bytesData())
108+
.outputDirectory(OUTPUT_DIRECTORY.getAbsolutePath())
109+
.debug()
110+
.build();
111+
112+
RemoteClustering remoteClustering = new RemoteClustering();
113+
114+
// When
115+
ClusteringRequestResult result = remoteClustering.request("http://localhost:8080", req);
116+
117+
// Then
118+
ClusteringRequestResult expected = expectedClusteringResultWithMediation();
79119
Assertions.assertThat(result).isEqualTo(expected);
80120
}
81121

@@ -87,9 +127,15 @@ private BytesDataArray bytesDataWithBytes() throws IOException {
87127
return (BytesDataArray)jsonGenericHandler.getObjectFromJsonFile(BytesDataArray.class, new File(getClass().getResource("/bytes-data-animals-dna.json").getFile()));
88128
}
89129

90-
private ClusteringRequestResult expectedClusteringResult(boolean bytesDataMode) throws IOException {
91-
File file = new File(getClass().getResource(
92-
bytesDataMode ? "/expected-clustering-result-bytes-data.json" : "/expected-clustering-result.json").getFile());
130+
private ClusteringRequestResult expectedClusteringResult() throws IOException {
131+
132+
File file = new File(getClass().getResource("/expected-clustering-result-bytes-data-animals-dna.json").getFile());
133+
return (ClusteringRequestResult) jsonGenericHandler.getObjectFromJsonFile(ClusteringRequestResult.class, file);
134+
}
135+
136+
private ClusteringRequestResult expectedClusteringResultWithMediation() throws IOException {
137+
138+
File file = new File(getClass().getResource("/expected-clustering-result-bytes-data-files-animals-dna.json").getFile());
93139
return (ClusteringRequestResult) jsonGenericHandler.getObjectFromJsonFile(ClusteringRequestResult.class, file);
94140
}
95141

File renamed without changes.

0 commit comments

Comments
 (0)