Skip to content

Commit

Permalink
Fixed empty named VC path in configuration (solves #754)
Browse files Browse the repository at this point in the history
Change-Id: I0eb93b056f095c0fb75746842ee636586711a44a
  • Loading branch information
margaretha committed Jun 11, 2024
1 parent c7f8f80 commit d151c30
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Cleaned up named-vc.
- Updated tests using the old match info web-services (#757)
- Added deprecation warning for the old matchInfo service (#757)
- Fixed empty named VC path in configuration (solves #754)

# version 0.73.1

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<jetty.version>11.0.19</jetty.version>
<flyway.version>10.6.0</flyway.version>
<log4j.version>2.22.1</log4j.version>
<krill.version>[0.62.4,)</krill.version>
<krill.version>[0.62.5,)</krill.version>
<koral.version>[0.42,)</koral.version>
</properties>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public KustvaktConfiguration (Properties properties) throws Exception {
load(properties);
// readPipesFile("pipes");
KrillProperties.setProp(properties);
KrillProperties.updateConfigurations(properties);
}

public KustvaktConfiguration () {}
Expand All @@ -145,7 +146,6 @@ public void loadBasicProperties (Properties properties) {
*/
protected void load (Properties properties) throws Exception {
loadBasicProperties(properties);
loadKrillProperties(properties);

apiWelcomeMessage = properties.getProperty("api.welcome.message",
"Welcome to KorAP API!");
Expand Down Expand Up @@ -222,26 +222,6 @@ protected void load (Properties properties) throws Exception {
networkEndpointURL = properties.getProperty("network.endpoint.url", "");
}

private void loadKrillProperties (Properties properties) {
try {
String maxTokenMatch = properties.getProperty("krill.match.max.token");
if (maxTokenMatch != null) {
KrillProperties.maxTokenMatchSize = Integer.parseInt(maxTokenMatch);
}

String maxTokenContext = properties
.getProperty("krill.context.max.token");
if (maxTokenContext != null) {
KrillProperties.maxTokenContextSize = Integer
.parseInt(maxTokenContext);
}
}
catch (NumberFormatException e) {
log.error("A Krill property expects numerical values: "
+ e.getMessage());
};
}

@Deprecated
public void readPipesFile (String filename) throws IOException {
File file = new File(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,18 @@ public void testGetStatisticsWithoutKoralQuery ()
assertEquals(25074, node.at("/sentences").asInt());
assertEquals(772, node.at("/paragraphs").asInt());
}

@Test
public void testStatisticsWithNamedVC () throws KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("cq", "referTo unknownVC")
.request().method("GET");
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
assertEquals(0, node.at("/documents").asInt());
assertEquals(0, node.at("/tokens").asInt());
assertEquals(0, node.at("/sentences").asInt());
assertEquals(0, node.at("/paragraphs").asInt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;

public class VCReferenceTest extends SpringJerseyTest {
public class VirtualCorpusReferenceTest extends SpringJerseyTest {

@Autowired
private NamedVCLoader vcLoader;
Expand Down Expand Up @@ -130,14 +130,27 @@ private JsonNode testSearchWithRef_VC2 () throws KustvaktException {
public void testStatisticsWithRef () throws KustvaktException {
String corpusQuery = "availability = /CC-BY.*/ & referTo named-vc1";
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", corpusQuery).request().get();
.queryParam("cq", corpusQuery).request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(2, node.at("/documents").asInt());
VirtualCorpusCache.delete("named-vc1");
assertFalse(VirtualCorpusCache.contains("named-vc1"));
}

@Test
public void testStatisticsWithUnknownVC () throws KustvaktException {
String corpusQuery = "referTo unknown-vc";
Response response = target().path(API_VERSION).path("statistics")
.queryParam("cq", corpusQuery).request().get();
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
assertEquals(0, node.at("/documents").asInt());
assertEquals(0, node.at("/tokens").asInt());
assertEquals(0, node.at("/sentences").asInt());
}

@Test
public void testRefVcNotExist () throws KustvaktException {
Response response = target().path(API_VERSION).path("search")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,18 @@ public void testGetStatisticsWithoutKoralQuery ()
assertEquals(25074, node.at("/sentences").asInt());
assertEquals(772, node.at("/paragraphs").asInt());
}

@Test
public void testStatisticsWithNamedVC () throws KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("cq", "referTo unknownVC")
.request().method("GET");
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
assertEquals(0, node.at("/documents").asInt());
assertEquals(0, node.at("/tokens").asInt());
assertEquals(0, node.at("/sentences").asInt());
assertEquals(0, node.at("/paragraphs").asInt());
}
}

0 comments on commit d151c30

Please sign in to comment.