ROS Mapping version 1.0
New Features of Version 1.0
- The new version allows the user to specify the rhetorical category. Users can specify one or more rhetorical category.
- The user also have an option to choose the semantic similarity metrics. Though it is highly advised to stick to the default semantic similarity measure (which is Lin similarity measure), in this version users have option to choose other similarity measures (wu&Palmer, Path, Lesk, etc).
- An optimized version of loading graphs into memory to avoid multiple calls to the neo4j server is introduced. Users can load all the graphs once and use them from memory.
- Additional attribute is added to the mapping JSON file to indicate whether the visualization component show or hide a specific pair of the mapping. This allows for a better visualization of the mapping components by hiding less informative pairs.
- A new method is added to access the frequency of the mappings of two nouns or verb.
Important:
When changing the similarity metrics, makes sure that you also clean previous scores from similarity score database. Otherwise, the old metrics and the new metrics will mix up and result inconsistent score.
Resources
- Javadoc Java documentation of the library
- Download Jar The Jar file including its dependent libraries. Here is the latest version for addressing ROSInteract instance.
- Similarity Score (Lin) Stored similarity score from previous runs to improve speed (New).
- Example file Example
- Example file 4 unix Example
Prerequisite
- Download and configure GenerateROS GenerateROS to access existing ROS or to generate new ROS for your papers.
- Put the latest GenerateROS.dll, libcurl.dll and settings.txt under your java project folder.
- Make sure mysql is up and running with your username and password. Note that for setting up a new database, you need to have privilege to create a database in your mysql server. For performance improvement turn on mysql database. The library can work without mysql turned on but it will be slower as it calculates similarity directly from WordNet.
- Make sure neo4j is up and running with your username and password.
- Make sure that you have the paper id of the source and the target papers.
- Java jdk 1.6 or latest version installed and running on your machine.
How to run
- Download the jar file from Generate Mapping This file contains the jar file and all the associated dependent files and libraries.
- Extract the downloaded file to your preferred location.
- In your java project, add the jar file as a library
- Put the GenerateROS.dll, libcurl.dll and ROSIneract.properties under your java project folder. Make sure that you have the latest version for each.
- If you are a first time user, it is recommended to use the "Example.java" file to run the program.
How to use the Library to generate mappings
To run analogy between two papers (in this case ROS), you need to have the neo4j id of the source and the target graphs. To load these graphs into memory you need declare the following classes.
First, in your main method, create AnalogyMapper class which facilitates loading properties files, setting similarity metrics and
selecting rhetorical categories.
AnalogyMapper mapper = new AnalogyMapper();
Then, load the settings from the properties file, if you didn't do this already.
Note: If you already load ROSInteract in your code, doing it the second time will cause a problem.
If you are using a unix system you should replace this method with
Note: If you already load ROSInteract in your code, doing it the second time will cause a problem.
mapper.loadROSInteract();
This method essentially calls the following lines to load the dll file for the ROSInteract component and reads all the settings from the ROSInteract.properties file. String classPath = System.getProperty("user.dir");
System.load(classPath + "\\GenerateROS.dll");
ros = new ROSInteract(classPath + "\\ROSInteract.properties");If you are using a unix system you should replace this method with
mapper.loadROSInteractUnix();
If you are running this model for the first time and do not have the similarityscore database created, include the following line.
Make sure the user has a privilege to create a new database.
mapper.setupdb("root", "");
Choose the WordNet metrics you would like to use here. The default metrics is Lin.
Use the WN_METRICS enum to see list of implemented metrics.
mapper.setSimMetrics(WN_METRICS.LIN);
Define your rhetorical categories. E.g.
int[] rhetCat = new int[]{RHETORICAL_CATEGORY.ABSTRACT.getValue(), RHETORICAL_CATEGORY.BACKGROUND.getValue()};
Set the neo4j Ids of the graphs you would like to compare. You have two options to pass the ids.
- Passing the two graph ids using the following code with no rhetorical category (uses the full graph). E.g.
map = mapper.Map(1, 2); - Passing the two graph ids and their rhetorical categories using the following code. E.g.
map = mapper.Map(1,rhetCatS, 2, rhetCatT); //including the source and the target rhetorical category you want.
Loading multiple graphs into memory and running mapping from graphs loaded in memory. In memory graph speeds up things when you have large memory.
It avoids repetitive calls to the neo4j server and it loads the required graph into memory only once.
- First create two arrays of neo4j graph id and populate your graph ids in the source and the target arrays respectively. E.g.
int sGraphIds[] = new int[1000];
int tGraphIds[] = new int[1000];
for (int i = 0; i < 1000; i++) {
sGraphIds[i] = i + 1;
tGraphIds[i] = i + 1;
} - Second load the graphs into memory using the following code.
mapper.loadInMemoryGraph(sGraphIds, rhetCatS, tGraphIds, rhetCatT); - Using the following code get a reference to the loaded graph.
ROSGraph[] inMemoryGraph = mapper.getInMemoryGraph(); - Using the following map to retrieve the source and the target graph index, iterate through each target and source to map all the source graphs
to all the target graphs. See the example provided for details of the code.
String result = "";
int[] sGraphIds = new int[1000];
for (int i = 0; i < 1000; i++) {
sGraphIds[i] = i + 1;
}
int[] tGraphIds = new int[]{1, 2, 3,4,5,6,7,8,9,10};
StringBuilder result = new StringBuilder("");
//load your graph in memory here.
mapper.loadInMemoryGraph(sGraphIds, rhetCatS, tGraphIds, rhetCatT);
ROSGraph G1 = null, G2 = null;
//here you can pass any combination of the source and the target. But make sure that you use the correct array index corresponding to
//the graph id you are interested in. You may use the sMap ant tMap which are Map objects between array index and neo4jid.
for (Integer entry : mapper.getTmap().keySet()) {
result.append(map.getMetricsHeader()).append("\n");
try {
G2 = mapper.getInMemoryGraph()[entry];
for (Integer sentry : mapper.getSmap().keySet()) {
G1 = mapper.getInMemoryGraph()[sentry];
map = mapper.generateMapping(G1, G2);
//do what ever you want with map
result.append(map.getMetrics()).append("\n");
System.out.println(map.getMetrics() + "\n");
G1 = null;
}
String fileName = "Your location\\CASAEvaluation\\Experiment2\\" + G2.getGraphId() + ".csv";
FileWriter fw = new FileWriter();
fw.writeToFile(fileName, result.toString());
G2 = null;
result.setLength(0);
} catch (Exception e) {
System.out.println("There is a problem mapping graph:: " + entry);
}
}
Call generateMapping(ROSGraph,ROSGraph) by passing your source and target graph in that order.E.g.
G1 is the source graph and G2 is the target graph. Switching this order will result a different mapping.
map = mapper.generateMapping(G1, G2);G1 is the source graph and G2 is the target graph. Switching this order will result a different mapping.
You can get all the information contained in the map using the methods defined by the ROSMap class. For Example,
map.getMapSize(); // to get the mapping size
map.getAnalogicalSimilarity(); // to get the analogical similarity value
map.getMappingNodePairs().get(0).getSourceNodeId();// to get the first mapping pair's source node id.
map.getMappingNodePairs().get(0).getTargetNodeId(); // to get the first mapping pair's target node id.
map.getMappingNodePairs().get(0).getSimScore();// to get the first mapping pair's similarity score.
map.getMappingNodePairs().get(0).isVisible();//// to get whether this pair needs to be visible.
You can extract the mapping results in different formats.
JSON Format
CSV Format
Metrics
JSON Format
System.out.println(bestmap.getMapInJSON()); CSV Format
System.out.println(bestmap.getMapInCSV());Metrics
System.out.println(map.getMetrics());
If you decide to directly interact with the mapping classes and methods without using the mapper class, please see the source code for the
AnalogyMapper class provided. In addition to this documentation of each class provided should guide you to write your own application of analogy mapping.
How to report bugs
This is an initial implementation and by no means is complete. We expect more comments and bug reports from other groups. Please report any bug or forward your questions to abgaz.yalemisew@nuim.ie or report it on redmine.
Previous versions
Click here For previous versions.
Last updated May 04, 2016
This research project receives funding from the European Commission Seventh Framework Programme. Activity ICT (FP7-ICT-2013.8.1), Grant agreement no: 611383.
This research project receives funding from the European Commission Seventh Framework Programme. Activity ICT (FP7-ICT-2013.8.1), Grant agreement no: 611383.