Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Windows support for Redis #372

Merged
merged 6 commits into from
Mar 14, 2014
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package eu.excitementproject.eop.biutee.rteflow.systems.excitement;

import java.io.File;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -133,17 +132,39 @@ private static void doTesting(CommonConfig config) throws EDAException, Componen
}
logger.trace(String.format("Processing all %d xmi files in %s using BiuteeEDA...", xmiFiles.length, lapOutputFolder));

List<Boolean> results = new ArrayList<Boolean>();
double tp=0,fp=0,tn=0,fn=0;
//List<Boolean> res = new ArrayList<Boolean>();
for (File xmi : xmiFiles) {
JCas jcas = PlatformCASProber.probeXmi(xmi, null);
TEDecision decision = eda.process(jcas);
DecisionLabel gold = readGoldLabel(jcas, xmi);
results.add(gold.equals(decision.getDecision()));
//res.add(gold.equals(decision.getDecision()));

if (gold.equals(decision.getDecision())) {
if (decision.getDecision() == DecisionLabel.Entailment)
tp++;
else
tn++;
} else {
if (decision.getDecision() == DecisionLabel.Entailment)
fp++;
else
fn++;
}

logger.info(String.format("Decision for %s: label=%s, confidence=%f", xmi, decision.getDecision(), decision.getConfidence()));
}

double accuracy = (tp + tn) / (tp + fp + tn + fn);
double precision = tp / (tp + fp);
double recall = tp / (tp + fn);
double f1 = 2 * ((precision * recall) / (precision + recall));

logger.trace(String.format("Finished processing %d xmi files using BiuteeEDA.", xmiFiles.length));
logger.info("Accuracy: " + calcAccuracy(results));
logger.info("Accuracy: " + accuracy);
logger.info("Precision: " + precision);
logger.info("Recall: " + recall);
logger.info("F1: " + f1);
}
finally {
if (eda != null) {
Expand All @@ -152,15 +173,15 @@ private static void doTesting(CommonConfig config) throws EDAException, Componen
}
}

private static double calcAccuracy(List<Boolean> results) {
/* private static double calcAccuracy(List<Boolean> results) {
int correct = 0;
for (Boolean result : results) {
if (result) {
correct++;
}
}
return ((double)correct) / results.size();
}
}*/

private static DecisionLabel readGoldLabel(JCas jcas, File xmi) throws EDAException {
DecisionLabel goldLabel = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,28 @@ public class SimilarityStorageBasedDIRTSyntacticResource extends SyntacticResour
* @throws FileNotFoundException
*/
public SimilarityStorageBasedDIRTSyntacticResource(ConfigurationParams params) throws ConfigurationException, ElementTypeException, FileNotFoundException, RedisRunException {
this(
new DefaultSimilarityStorage(params),
new DependencyPathsFromTreeBinary<Info, BasicNode>(new BasicNodeConstructor(), new DependencyPathsFromTree.VerbAdjectiveNounPredicate<Info>(), true, true),
params.getInt(Configuration.TOP_N_RULES)
);
String hostLeft = null;
int portLeft = -1;
try {
hostLeft = params.get(Configuration.L2R_REDIS_HOST);
portLeft = params.getInt(Configuration.L2R_REDIS_PORT);
} catch (ConfigurationException e) {
}
this.maxNumOfRetrievedRules = params.getInt(Configuration.TOP_N_RULES);

if (hostLeft == null || portLeft == -1)
this.similarityStorage = new DefaultSimilarityStorage(params);
else {
String instanceName = "";
try {
instanceName = params.get(Configuration.INSTANCE_NAME);
} catch (ConfigurationException e) {
instanceName = params.getConfigurationFile().toString();
}
this.similarityStorage = new DefaultSimilarityStorage(hostLeft,portLeft,params.get(Configuration.RESOURCE_NAME),instanceName);
}
this.extractor = new DependencyPathsFromTreeBinary<Info, BasicNode>(new BasicNodeConstructor(), new DependencyPathsFromTree.VerbAdjectiveNounPredicate<Info>(), true, true);
this.matchCriteria = new BasicMatchCriteria<Info,Info,BasicNode,BasicNode>();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;


import eu.excitementproject.eop.common.datastructures.immutable.ImmutableIterator;
import eu.excitementproject.eop.distsim.items.Element;
import eu.excitementproject.eop.distsim.items.Feature;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class CompareElementFeatureData {
public static void main(String[] args) throws LoadingStateException, IOException, ItemNotFoundException, UndefinedKeyException, InvalidCountException {

if (args.length != 3 && args.length != 4) {
System.out.println("Usage: java eu.excitementproject.eop.distsim.application.CompareItemData <in dir 1> <in dir 2> <item-pair file name> [<check elements and features>, default no]");
System.out.println("Usage: java eu.excitementproject.eop.distsim.application.CompareElementFeatureData <in dir 1> <in dir 2> <item-pair file name> [<check elements and features>, default no]");
System.exit(0);
}

Expand All @@ -46,12 +47,15 @@ public static void main(String[] args) throws LoadingStateException, IOException
file1.open();
elementFeatureData1.loadState(file1);
file1.close();


IDKeyPersistentBasicMap<BasicMap<Integer,Double>> elementFeatureData2 = new TroveBasedIDKeyPersistentBasicMap<BasicMap<Integer,Double>>();
File file2 = new IdTroveBasicIntDoubleMapFile(new java.io.File(dir2 + "/" + args[2]),true);
file2.open();
elementFeatureData2.loadState(file2);
file2.close();


file1 = new File(new java.io.File(dir1 + "/elements"),true);
file1.open();
MemoryBasedCountableIdentifiableStorage<Element> elements1 = new MemoryBasedCountableIdentifiableStorage<Element>(file1);
Expand Down Expand Up @@ -85,7 +89,7 @@ public static void main(String[] args) throws LoadingStateException, IOException
file2.open();
MemoryBasedCountableIdentifiableStorage<Feature> features2 = new MemoryBasedCountableIdentifiableStorage<Feature>(file2);
file2.close();

//compare features
if (bCheckElementsAndFeatures) {
System.out.println("comparing features");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CompareElementSimilarities {
public static void main(String[] args) throws LoadingStateException, IOException, ItemNotFoundException, UndefinedKeyException, InvalidCountException {

if (args.length != 3) {
System.out.println("Usage: java eu.excitementproject.eop.distsim.application.CompareItemData <in dir 1> <in dir 2> <item-pair file name>");
System.out.println("Usage: java eu.excitementproject.eop.distsim.application.CompareElementSimilarities <in dir 1> <in dir 2> <similarity file name>");
System.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CompareFeatureElements {
public static void main(String[] args) throws LoadingStateException, IOException, ItemNotFoundException, UndefinedKeyException {

if (args.length != 3) {
System.out.println("Usage: java eu.excitementproject.eop.distsim.application.CompareItemData <in dir 1> <in dir 2> <compared file name>");
System.out.println("Usage: java eu.excitementproject.eop.distsim.application.CompareFeatureElements <in dir 1> <in dir 2> <compared file name>");
System.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public static void main(String[] args) throws Exception {
String redisFile = args[0];
int port = Integer.parseInt(args[1].trim());
String redisConfFile = BasicRedisRunner.generateConfigurationFile(redisFile, port);
Runtime.getRuntime().exec(new String[]{BasicRedisRunner.DEFAULT_REDIS_BIN_DIR + "/" + BasicRedisRunner.REDIS_SERVER_CMD,redisConfFile});
Runtime.getRuntime().exec(new String[]{BasicRedisRunner.DEFAULT_REDIS_BIN_DIR + "/" + BasicRedisRunner.getRedisServerCmd(),redisConfFile});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@SuppressWarnings("rawtypes")
public class GeneralCooccurrenceExtractor implements CooccurrencesExtractor {

private static Logger logger = Logger.getLogger(GeneralCooccurrenceExtractor.class);
//private static Logger logger = Logger.getLogger(GeneralCooccurrenceExtractor.class);
/*
public GeneralCooccurrenceExtractor(int iThreadNum, CooccurrenceExtraction cooccurrenceExtraction,FileBasedSentenceReader sentenceReader, DataStructureFactory dataStructureFactory) {
this.iThreadNum = iThreadNum;
Expand All @@ -57,9 +57,10 @@ public GeneralCooccurrenceExtractor(int iThreadNum, CooccurrenceExtraction coocc

public GeneralCooccurrenceExtractor(ConfigurationParams params,DataStructureFactory dataStructureFactory) throws ConfigurationException, CreationException {
this.iThreadNum = params.getInt(Configuration.THREAD_NUM);
if (iThreadNum > 1) {
/*if (this.iThreadNum > 1) {
logger.warn("Multi-threading is temporarilly not supported - a single thread will be applied instead");
}
this.iThreadNum = 1;
}*/
this.confParams = params;
this.textUnitStorage = dataStructureFactory.createTextUnitsDataStructure();
this.cooccurrenceStorage = dataStructureFactory.createCooccurrencesDataStucture();
Expand All @@ -77,7 +78,7 @@ public CooccurrenceStorage constructCooccurrenceDB(File corpus) throws Cooccurre
Set<File> files = FileUtils.getFiles(corpus);

//tmp
System.out.println("total number of files: " + files.size());
//System.out.println("total number of files: " + files.size());

int filesPerCollector = files.size() / iThreadNum;
if (files.size() % iThreadNum > 0)
Expand Down Expand Up @@ -114,7 +115,7 @@ public CooccurrenceStorage constructCooccurrenceDB(File corpus) throws Cooccurre
}
}

protected final int iThreadNum;
protected int iThreadNum;
protected final ConfigurationParams confParams;
protected CountableIdentifiableStorage<TextUnit> textUnitStorage;
protected CountableIdentifiableStorage<IDBasedCooccurrence> cooccurrenceStorage;
Expand All @@ -130,7 +131,7 @@ class CooccurrenceCollector implements Runnable {
this.cooccurrenceExtraction = (CooccurrenceExtraction) Factory.create(confParams.get(Configuration.EXTRACTION_CLASS), confParams);

//tmp
System.out.println("Thread " + id + ": got " + files.size() + " files");
//System.out.println("Thread " + id + ": got " + files.size() + " files");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public void run() {
break;
}


// extract element and feature from the given co-occurrence, and store their counts
try {

Expand Down Expand Up @@ -225,8 +224,8 @@ public void run() {
System.out.println(e.toString());
} catch (Exception e) {
logger.error(ExceptionUtil.getStackTrace(e));
}
}
}
}

System.out.println(c + " cooccurrences were processed by extractor " + threadID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,8 @@ public void run() {

//compute element-feature scores
try {



Element element = elementFeaturecounts.getElement(elementFeatureJointCount.getElementId());

ImmutableIterator<FeatureCount> featureCounts = elementFeatureJointCount.getFeatureCounts();

Element element = elementFeaturecounts.getElement(elementFeatureJointCount.getElementId());
ImmutableIterator<FeatureCount> featureCounts = elementFeatureJointCount.getFeatureCounts();
// measure the score for each feature, based on its counts
Map<Integer,Double> tmpCommonScoredFeatures = new HashMap<Integer,Double>();
Map<Integer,Double> tmpScoredFeatures = new HashMap<Integer,Double>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LemmaPosTextUnit(LemmaPos data, int id, long count) {
}

@Override
public TextUnit copy() {
public synchronized TextUnit copy() {
return new LemmaPosTextUnit(data, id,(long)count);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.BufferedReader;



import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
Expand All @@ -21,6 +22,7 @@

import org.apache.log4j.Logger;

import eu.excitementproject.eop.common.utilities.OS;
import eu.excitementproject.eop.common.utilities.configuration.ConfigurationException;
import eu.excitementproject.eop.common.utilities.configuration.ConfigurationParams;
import eu.excitementproject.eop.distsim.util.Configuration;
Expand Down Expand Up @@ -153,7 +155,6 @@ public class BasicRedisRunner implements RedisRunner {
protected static final String PID_FILE_EXT = ".pid";
protected static final String VM_SWAP_FILE_EXT = ".swap";
protected static final String DB_FILE_EXT = ".rdb";
public static final String REDIS_SERVER_CMD = "redis-server";

protected static RedisRunner instance = null;
protected static String redisBinDir; //a path to the Redis binary directory
Expand All @@ -165,9 +166,10 @@ public class BasicRedisRunner implements RedisRunner {
*
* @return a singleton instance of BasicRedisRunner
*
* @throws FileNotFoundException in case the default redis binary directory and/or the default configuration file are not existed
* @throws RedisRunException in case the default redis binary directory and/or the default configuration file are not existed
* or does not support current OS
*/
public synchronized static RedisRunner getInstance() throws FileNotFoundException {
public synchronized static RedisRunner getInstance() throws RedisRunException {
if (instance == null) {
instance = new BasicRedisRunner();
}
Expand All @@ -180,13 +182,18 @@ public synchronized static RedisRunner getInstance() throws FileNotFoundExceptio
* @param templateConfigurationFile a path to a Redis configuration file
* @return a singleton instance of BasicRedisRunner
*
* @throws FileNotFoundException in case the default redis binary directory and/or the default configuration file are not existed
* @throws RedisRunException in case the default redis binary directory and/or the default configuration file are not existed,
* or does not support current OS
*/
public synchronized static RedisRunner getInstance(String templateConfigurationFile) throws FileNotFoundException {
public synchronized static RedisRunner getInstance(String templateConfigurationFile) throws RedisRunException {
if (instance == null) {
instance = new BasicRedisRunner();
}
((BasicRedisRunner)instance).setRedisConfigurationFileTemplate(templateConfigurationFile);
try {
((BasicRedisRunner)instance).setRedisConfigurationFileTemplate(templateConfigurationFile);
} catch (FileNotFoundException e) {
throw new RedisRunException(e);
}
return instance;
}

Expand Down Expand Up @@ -214,9 +221,10 @@ public synchronized static void setRedisBinDir(String redisBinDir) throws Redis
*
* @return a singleton instance of BasicRedisRunner
*
* @throws FileNotFoundException in case the configured redis binary directory and/or configuration template file are not existed
* @throws RedisRunException in case the configured redis binary directory and/or configuration template file are not existed
* or does not support current OS
*/
public synchronized static RedisRunner getInstance(ConfigurationParams params) throws FileNotFoundException {
public synchronized static RedisRunner getInstance(ConfigurationParams params) throws RedisRunException {
if (instance == null) {
try {
BasicRedisRunner.redisBinDir = params.get(Configuration.REDIS_BIN_DIR);
Expand All @@ -227,6 +235,8 @@ public synchronized static RedisRunner getInstance(ConfigurationParams params) t

try {
((BasicRedisRunner)instance).setRedisConfigurationFileTemplate(params.get(Configuration.REDIS_CONFIGURATION_TEMPLATE_FILE));
} catch (FileNotFoundException e) {
throw new RedisRunException(e);
} catch (ConfigurationException e) {
}

Expand All @@ -236,14 +246,15 @@ public synchronized static RedisRunner getInstance(ConfigurationParams params) t
/**
* Constructs BasicRedisRunner, based on a default location of the Redis binary directory (.) and a default location of the Redis configuration template file (desc/redis.conf)
*
* @throws FileNotFoundException in case the default redis binary directory and/or the default configuration file are not existed
* @throws RedisRunException in case the default redis binary directory and/or the default configuration file are not existed,
* or does not support current OS
*/
private BasicRedisRunner() throws FileNotFoundException {
private BasicRedisRunner() throws RedisRunException {
this.templateConfigurationFile = redisBinDir + "/" + DEFAULT_TEMPLATE_CONFIGURATION_FILE_NAME;
this.mapDir2FileInstanceInfo = new HashMap<String,RedisInstanceInfo>();
this.usedPorts = new HashSet<Integer>();
if (!new File(redisBinDir + "/" + REDIS_SERVER_CMD).exists())
throw new FileNotFoundException("Redis server executable was not found: " + redisBinDir + "/" + REDIS_SERVER_CMD + ". Recheck the redis server directory argument");
if (!new File(redisBinDir + "/" + getRedisServerCmd()).exists())
throw new RedisRunException("Redis server executable was not found: " + redisBinDir + "/" + getRedisServerCmd() + ". Recheck the redis server directory argument");
//this.executor = new DefaultExecutor();
}

Expand Down Expand Up @@ -317,7 +328,7 @@ public void onProcessFailed(ExecuteException e) {
logger.warn(e.toString());
}
});*/
Process process = Runtime.getRuntime().exec(new String[]{redisBinDir + "/" + REDIS_SERVER_CMD,confFile});
Process process = Runtime.getRuntime().exec(new String[]{redisBinDir + "/" + getRedisServerCmd(),confFile});
waitForRedisInitializing(process);

logger.info("The redis server on port " + port + ", based on " + confFile + " configuration, is ready now");
Expand Down Expand Up @@ -534,7 +545,16 @@ public static void main(String[] args) {

}


public static String getRedisServerCmd() throws RedisRunException {
if (OS.isLinux() || OS.isUnix())
return "redis-server";
if (OS.isWindows())
return "redis-server.exe";
throw new RedisRunException("Current operating system does not support Redis servewr execution");
}

static {
redisBinDir = DEFAULT_REDIS_BIN_DIR;
redisBinDir = DEFAULT_REDIS_BIN_DIR;
}
}
Loading