Skip to content
Snippets Groups Projects
Commit 3f80c67e authored by Eike Cochu's avatar Eike Cochu
Browse files

fixed modeling problems with small models, fixed partial updating database

parent 575d15b3
Branches
No related tags found
No related merge requests found
......@@ -13,6 +13,14 @@ This application was created by Eike Cochu for his master's degree thesis in com
## Installation
1. If MongoDB or ElasticSearch run on different servers that the JavaEE application server, then the configuration files need to be changed. Change `config.properties` file
1. in `vipra.war`: Open `vipra.war` in an archive program, navigate to `/WEB-INF/classes` and edit `config.properties` file appropriately.
2. in `vipra-cmd.jar`: Open `vipra-cmd.jar` and edit `config.properties` file appropriately.
3. Test connection by running `./vipra -t`
2. Copy `vipra.war` to your JavaEE application server
## Development
### Requirements
Run dependencies
......@@ -29,7 +37,7 @@ Additional build dependencies
* [Gulp (3.9+)](http://gulpjs.com/)
* [Bower (1.7+](http://bower.io/)
### Installation
### Build
1. Clone this repository to `./vipra`
2. Navigate to `./vipra`
......
db.host=localhost
db.port=27017
db.name=test
es.host=localhost
es.port=9300
tm.processor=corenlp
tm.analyzer=jgibb
tm.dtmpath=/home/eike/repos/master/dtm_release/dtm/main
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/vipra-cmd/src/main/java/de/vipra/cmd/Main.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.vipra.cmd.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-e"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="vipra-cmd"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dlog4j.configurationFile=log4j2dev.xml"/>
</launchConfiguration>
......@@ -107,21 +107,24 @@ public class JGibbAnalyzer extends Analyzer {
List<TopicFull> newTopics = new ArrayList<>(options.K);
Map<Integer, Topic> newTopicsMap = new HashMap<>(options.K);
// for each topic
for (int topicNum = 0; topicNum < options.K; topicNum++) {
TopicFull newTopic = new TopicFull();
List<TopicWord> topicWords = new ArrayList<>(options.twords);
// for each word
for (int wordNum = 0, lineNum = topicNum * options.K + 1; wordNum < options.twords; wordNum++, lineNum++) {
String[] parts = lines.get(lineNum).trim().split("\\s+");
TopicWord topicWord = new TopicWord(new Word(parts[0]), Double.parseDouble(parts[1]));
topicWords.add(topicWord);
}
TopicFull newTopic = null;
List<TopicWord> topicWords = null;
int topicNum = 0;
// for each line
for (String line : lines) {
if (!line.startsWith("\t")) {
newTopic = new TopicFull();
topicWords = new ArrayList<>();
newTopic.setWords(topicWords);
newTopics.add(newTopic);
newTopicsMap.put(topicNum, new Topic(newTopic.getId()));
newTopicsMap.put(topicNum++, new Topic(newTopic.getId()));
continue;
}
String[] parts = line.trim().split("\\s+");
TopicWord topicWord = new TopicWord(new Word(parts[0]), Double.parseDouble(parts[1]));
topicWords.add(topicWord);
}
dbTopics.drop();
......
db.host=localhost
db.port=27017
db.name=test
es.host=localhost
es.port=9300
tm.processor=corenlp
tm.analyzer=jgibb
tm.dtmpath=/home/eike/repos/master/dtm_release/dtm/main
\ No newline at end of file
......@@ -51,6 +51,18 @@ public class Config {
@ConfigKey("db.name")
public String databaseName = Constants.DATABASE_NAME;
/**
* ElasticSearch host
*/
@ConfigKey("es.host")
public String elasticsearchHost = Constants.ES_HOST;
/**
* ElasticSearch connection port
*/
@ConfigKey("es.port")
public int elasticsearchPort = Constants.ES_PORT;
/**
* The text processor to be used. To find a list of available values,
* {@link de.vipra.util.Constants.Processor}.
......
......@@ -23,8 +23,8 @@ public abstract class ESClient {
*/
public static TransportClient getClient(Config config) throws UnknownHostException {
if (client == null) {
client = TransportClient.builder().build().addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(Constants.ES_HOST), Constants.ES_PORT));
client = TransportClient.builder().build().addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName(config.elasticsearchHost), config.elasticsearchPort));
}
return client;
}
......
......@@ -41,7 +41,8 @@ public class MongoService<Type extends Model<IdType>, IdType> implements Service
field.setAccessible(true);
UpdateIgnore ui = field.getDeclaredAnnotation(UpdateIgnore.class);
this.updateFields.put(field.getName(), ui == null ? null : field);
if (ui == null)
this.updateFields.put(field.getName(), field);
QueryIgnore qi = field.getDeclaredAnnotation(QueryIgnore.class);
if (qi != null) {
......@@ -183,6 +184,7 @@ public class MongoService<Type extends Model<IdType>, IdType> implements Service
} else {
Query<Type> query = datastore.createQuery(clazz).field("_id").equal(t.getId());
UpdateOperations<Type> ops = datastore.createUpdateOperations(clazz);
boolean noChanges = true;
for (String fieldName : fields) {
if (!this.updateFields.containsKey(fieldName))
throw new DatabaseException("field unknown: " + fieldName);
......@@ -195,10 +197,12 @@ public class MongoService<Type extends Model<IdType>, IdType> implements Service
ops.unset(fieldName);
else
ops.set(fieldName, value);
noChanges = false;
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new DatabaseException(e);
}
}
if (!noChanges)
datastore.update(query, ops);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment