Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.tyndalehouse.step</groupId>
<artifactId>step-mvn</artifactId>
<version>26.4.9</version>
<version>26.6.3</version>
<packaging>pom</packaging>
<name>STEP :: Scripture Tools for Every pastor</name>

Expand Down
2 changes: 1 addition & 1 deletion step-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>step-mvn</artifactId>
<groupId>com.tyndalehouse.step</groupId>
<version>26.4.9</version>
<version>26.6.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion step-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.tyndalehouse.step</groupId>
<artifactId>step-mvn</artifactId>
<version>26.4.9</version>
<version>26.6.3</version>
</parent>

<artifactId>step-build</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion step-core-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.tyndalehouse.step</groupId>
<artifactId>step-mvn</artifactId>
<version>26.4.9</version>
<version>26.6.3</version>
</parent>

<artifactId>step-core-data</artifactId>
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion step-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.tyndalehouse.step</groupId>
<artifactId>step-mvn</artifactId>
<version>26.4.9</version>
<version>26.6.3</version>
</parent>

<groupId>com.tyndalehouse.step</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void init() {
loadData();
this.complete = true;
appManager.setAndSaveAppVersion(runningAppVersion);
appManager.setIsWWWServer();

} catch (Exception ex) {
//wrap it into an internal exception so that we get some logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected void doConfigure() {
bind(OriginalWordSuggestionService.class).to(OriginalWordSuggestionServiceImpl.class);
bind(SupportRequestService.class).to(SupportRequestServiceImpl.class);
bind(JSwordRelatedVersesService.class).to(JSwordRelatedVersesServiceImpl.class);
bind(SemanticRelatedVersesService.class).to(SemanticRelatedVersesServiceImpl.class).asEagerSingleton();

bind(new TypeLiteral<List<String>>() {
}).annotatedWith(Names.named("defaultVersions")).toProvider(DefaultVersionsProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SearchToken implements Serializable {
public static final String MEANINGS = "meanings";
public static final String TOPIC_BY_REF = "topicref";
public static final String RELATED_VERSES = "relatedrefs";
public static final String RELATED_VERSES_SEMANTIC = "relatedrefsSemantic";
public static final String EXACT_FORM = "exactForm";
public static final String SYNTAX = "syntax";
public static final String LIMIT = "limit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface AppManagerService {
*/
String APP_VERSION = "app.version";

String IS_WWW_SERVER = "false";

/**
* @return the currently installed version of the application
*/
Expand All @@ -20,6 +22,10 @@ public interface AppManagerService {
*/
void setAndSaveAppVersion(String newVersion);

boolean isWWWServer();

void setIsWWWServer();

File getStepInstallFile();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tyndalehouse.step.core.service;

import java.util.List;

public interface SemanticRelatedVersesService {
/** Returns ranked semantically-related NRSV verse OSIS refs for an NRSV input ref.
* Returns empty list if the ref is not in the dataset.
*
* CONTRACT: input MUST already be in NRSV versification. The dataset is
* NRSV-keyed by construction. Callers are responsible for inbound
* (user-v11n -> NRSV) and outbound (NRSV -> user-v11n) verse mapping.
* This service has no JSword dependency. */
List<String> getRelatedNrsvRefs(String nrsvOsisRef);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.util.Date;
import java.util.Properties;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Allows querying of app-specific properties, such as the installation properties
Expand Down Expand Up @@ -86,6 +86,34 @@ public void setAndSaveAppVersion(String newVersion) {
saveProperties();
}

@Override
public boolean isWWWServer() {
String result = appProperties.getProperty("IS_WWW_SERVER");
if ((result != null) && (result.equals("true")))
return true;
return false;
}

@Override
public void setIsWWWServer() {
File myObj = new File("/etc/hosts");
// try-with-resources: Scanner will be closed automatically
try (Scanner myReader = new Scanner(myObj)) {
Pattern pattern = Pattern.compile("127\\.0\\.0\\.1\\s+www\\.stepbible\\.org", Pattern.CASE_INSENSITIVE);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
Matcher matcher = pattern.matcher(data);
if (matcher.find()) {
appProperties.setProperty("IS_WWW_SERVER", "true");
return;
}
}
} catch (FileNotFoundException e) {
System.out.println("Cannot read /etc/hosts file. It is OK if this is not a server running for www.stepbible.org");
e.printStackTrace();
}
}

/**
* Saves the properties to disk.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public enum SearchType {
* Finds all verses that are related to another verse
*/
RELATED_VERSES("verse_related"),
/**
* Semantic related-verses lookup. Internal dispatch only — normalized to
* RELATED_VERSES on the wire by SearchServiceImpl#getBestSearchType.
*/
RELATED_VERSES_SEMANTIC("verse_related"),

/** A timeline description search */
TIMELINE_DESCRIPTION("search_timeline"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.tyndalehouse.step.core.service.impl;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.tyndalehouse.step.core.data.create.ModuleLoader;
import com.tyndalehouse.step.core.exceptions.StepInternalException;
import com.tyndalehouse.step.core.service.SemanticRelatedVersesService;

import javax.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

@Singleton
public class SemanticRelatedVersesServiceImpl implements SemanticRelatedVersesService {

private static final String RESOURCE_PATH =
"related-verses/bible_semantic_export_minified.json";

private final String[] pool;
private final int[][] related;

public SemanticRelatedVersesServiceImpl() {
final JsonFactory factory = new JsonFactory();
factory.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);

final InputStream stream = ModuleLoader.class.getResourceAsStream(RESOURCE_PATH);
if (stream == null) {
throw new StepInternalException("Unable to read resource: " + RESOURCE_PATH);
}

final HashMap<String, String[]> raw = new HashMap<String, String[]>(40_000);
final HashMap<String, String> internCache = new HashMap<String, String>(40_000);

try {
final JsonParser p = factory.createParser(stream);
try {
if (p.nextToken() != JsonToken.START_OBJECT) {
throw new StepInternalException("Expected JSON object at root: " + RESOURCE_PATH);
}

while (p.nextToken() == JsonToken.FIELD_NAME) {
final String key = p.getText();
if (p.nextToken() != JsonToken.START_ARRAY) {
throw new StepInternalException("Expected array at " + key);
}
final List<String> vals = new ArrayList<String>(100);
while (p.nextToken() != JsonToken.END_ARRAY) {
final String val = p.getText();
final String prev = internCache.putIfAbsent(val, val);
vals.add(prev != null ? prev : val);
}
raw.put(key, vals.toArray(new String[0]));
}
} finally {
p.close();
}
} catch (IOException e) {
throw new StepInternalException(
"Failed to load semantic related verses from " + RESOURCE_PATH + ": " + e.getMessage(), e);
} finally {
try { stream.close(); } catch (IOException ignored) { }
}

final TreeSet<String> union = new TreeSet<String>();
for (Map.Entry<String, String[]> e : raw.entrySet()) {
union.add(e.getKey());
for (String v : e.getValue()) {
union.add(v);
}
}

this.pool = union.toArray(new String[0]);
this.related = new int[this.pool.length][];

for (Map.Entry<String, String[]> e : raw.entrySet()) {
final int idx = Arrays.binarySearch(this.pool, e.getKey());
if (idx < 0) {
throw new StepInternalException("Pool missing key during finalization: " + e.getKey());
}
final String[] vals = e.getValue();
final int[] indices = new int[vals.length];
for (int i = 0; i < vals.length; i++) {
final int vIdx = Arrays.binarySearch(this.pool, vals[i]);
if (vIdx < 0) {
throw new StepInternalException("Pool missing value during finalization: " + vals[i]);
}
indices[i] = vIdx;
}
this.related[idx] = indices;
}
}

@Override
public List<String> getRelatedNrsvRefs(final String nrsvOsisRef) {
if (nrsvOsisRef == null || nrsvOsisRef.isEmpty()) return Collections.emptyList();
final int idx = Arrays.binarySearch(this.pool, nrsvOsisRef);
if (idx < 0 || this.related[idx] == null) return Collections.emptyList();
final int[] indices = this.related[idx];
final List<String> out = new ArrayList<String>(indices.length);
for (int i : indices) out.add(this.pool[i]);
return out;
}
}
Loading
Loading