Skip to content

Commit

Permalink
Graph lexicalization
Browse files Browse the repository at this point in the history
 - add statically the library word2vec ==> will change later with maven
 - compute the average number of vertice in a specific colour over the data typed properties
  • Loading branch information
Pham Thuy Sy Nguyen committed May 28, 2018
1 parent e7ec490 commit 2e96d42
Show file tree
Hide file tree
Showing 18 changed files with 844 additions and 435 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.bin
*.bin.gz
*.class
.classpath
.project
Expand Down
8 changes: 8 additions & 0 deletions config/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app.name=Word2Vec RESTful Web Service
app.description=${app.name} for models of code.google.com/p/word2vec
server.port=4441

spring.datasource.driverClassName=org.sqlite.JDBC
spring.datasource.url=jdbc:sqlite:word2vec.db
spring.datasource.username=root
spring.datasource.password=root
5 changes: 5 additions & 0 deletions config/cfg.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
org.aksw.word2vecrestful.web.Word2VecController.apikey: 1234
org.aksw.word2vecrestful.web.Word2VecController.maxN: 10000
org.aksw.word2vecrestful.word2vec.Word2VecModelLoader.bin: true
org.aksw.word2vecrestful.word2vec.Word2VecFactory.model: data/GoogleNews-vectors-negative300.bin
org.aksw.word2vecrestful.Application.inmemory: true
10 changes: 10 additions & 0 deletions config/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
log4j.rootLogger=INFO, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %5p [%t] (%F:%M:%L) - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log/root.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=100
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss} %5p [%t] (%F:%M:%L) - %m%n
Binary file added lib/jword2vec.jar
Binary file not shown.
171 changes: 76 additions & 95 deletions src/main/java/org/aksw/simba/lemming/ColouredGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import grph.algo.MultiThreadProcessing;
import grph.in_memory.InMemoryGrph;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -34,13 +35,6 @@ public class ColouredGraph{
/**
* this is new for processing the literals in the original RDF dataset
*/
//mapping vertex's colours to datatyped edge's colours
protected ObjectObjectOpenHashMap<BitSet, Set<BitSet>> mapVertexColoursToDataTypedEdgeColours;
//mapping datatyped edge's colours to set of literals
protected ObjectObjectOpenHashMap<BitSet, Set<String>> mapDTEdgeColoursToLiterals;
// map data typed edge's colours to set of connected vertex' ids
protected ObjectObjectOpenHashMap<BitSet, IntSet> mapDTEdgeColoursToVertexIDs;

protected Map<Integer, Map<BitSet, List<String>>> mapVertexIdAndLiterals;


Expand Down Expand Up @@ -80,10 +74,6 @@ public ColouredGraph(Grph graph, ColourPalette vertexPalette, ColourPalette edge
this.dtEdgePalette = datatypedEdgePalette;

mapVertexIdAndLiterals = new HashMap<Integer, Map<BitSet, List<String>>>();

mapVertexColoursToDataTypedEdgeColours = new ObjectObjectOpenHashMap<BitSet, Set<BitSet>>();
mapDTEdgeColoursToLiterals = new ObjectObjectOpenHashMap<BitSet, Set<String>>();
mapDTEdgeColoursToVertexIDs = new ObjectObjectOpenHashMap<BitSet, IntSet>();
}

public void removeEdge(int edgeId){
Expand Down Expand Up @@ -344,33 +334,24 @@ protected void run(int threadID, int vertId) {
/**
* Add a literal associated with the data typed property to the data store
* @param literal a literal
* @param tailId the vertex id which has the data typed property
* @param dtEdgeColour the data typed property's colour connecting to the vertex
* @param tId the vertex id which has the data typed property
* @param dteColo the data typed property's colour connecting to the vertex
*/
public void addLiterals(String literal, int tailId, BitSet dtEdgeColour){
public void addLiterals(String literal, int tId, BitSet dteColo){

BitSet vertColo = getVertexColour(tailId);

Set<BitSet> setDTEdgeColours = mapVertexColoursToDataTypedEdgeColours.get(vertColo);
if(setDTEdgeColours == null){
setDTEdgeColours = new HashSet<BitSet>();
mapVertexColoursToDataTypedEdgeColours.put(vertColo, setDTEdgeColours);
Map<BitSet, List<String>> mapDTEColoursToLiterals = mapVertexIdAndLiterals.get(tId);
if(mapDTEColoursToLiterals == null){
mapDTEColoursToLiterals = new HashMap<BitSet, List<String>> ();
mapVertexIdAndLiterals.put(tId, mapDTEColoursToLiterals);
}
setDTEdgeColours.add(dtEdgeColour);

Set<String> setLiterals = mapDTEdgeColoursToLiterals.get(dtEdgeColour);
if(setLiterals == null){
setLiterals = new HashSet<String>();
mapDTEdgeColoursToLiterals.put(dtEdgeColour, setLiterals);
List<String> lstOfLiterals = mapDTEColoursToLiterals.get(dteColo);
if(lstOfLiterals == null){
lstOfLiterals = new ArrayList<String>();
mapDTEColoursToLiterals.put(dteColo, lstOfLiterals);
}
setLiterals.add(literal);

IntSet setVertexIDs = mapDTEdgeColoursToVertexIDs.get(dtEdgeColour);
if(setVertexIDs == null){
setVertexIDs = new DefaultIntSet();
mapDTEdgeColoursToVertexIDs.put(dtEdgeColour, setVertexIDs);
}
setVertexIDs.add(tailId);
lstOfLiterals.add(literal);
}

/**
Expand All @@ -381,75 +362,20 @@ public void addLiterals(String literal, int tailId, BitSet dtEdgeColour){
public IntSet getVerticesIncidentToEdge(int edgeId){
return graph.getVerticesIncidentToEdge(edgeId);
}

/**
* Get a set of all associated data typed properties with the given vertex's colour
* @param vertexColour the colour of the vertex having data typed properties
* @return
*/
public Set<BitSet> getSetDTEdgeColours(BitSet vertexColour){
if(mapVertexColoursToDataTypedEdgeColours != null){
return mapVertexColoursToDataTypedEdgeColours.get(vertexColour);
}
return null;
}


/**
* Return all literals belonging to the data typed properties
* @param dtEdgeColour the data typed property's colour
* @return
* Get the set of data typed edge's colours which are connected to the vertex's colour
* @param vertexColour
* @return a set of linked edge's colours
*/
public Set<String> getSetLiterals(BitSet dtEdgeColour){
if(mapDTEdgeColoursToLiterals != null ){
return mapDTEdgeColoursToLiterals.get(dtEdgeColour);
public Set<BitSet> getDataTypedEdgeColours (BitSet vertexColour){
Map<BitSet, List<String>> mapDTEColoToLiterals = mapVertexIdAndLiterals.get(vertexColour);
if(mapDTEColoToLiterals != null){
return mapDTEColoToLiterals.keySet();
}
return null;
}

/**
* Get a map of the data typed properties with their sets of associated literals based on the vertex's color
*
* @param vertexColour the colour of the vertex which has the data typed properties
* @return
*/
public ObjectObjectOpenHashMap<BitSet, Set<String>> getMapDTEdgeColoursToLiterals(BitSet vertexColour){
ObjectObjectOpenHashMap mapRes = new ObjectObjectOpenHashMap<BitSet, Set<String>>();
if(mapVertexColoursToDataTypedEdgeColours != null && mapDTEdgeColoursToLiterals != null) {
Set<BitSet> setDTEdgeColours = mapVertexColoursToDataTypedEdgeColours.get(vertexColour);
if(setDTEdgeColours != null && setDTEdgeColours.size() > 0 ){
for(BitSet dtEdgeColo : setDTEdgeColours){
Set<String> setLiterals = mapDTEdgeColoursToLiterals.get(dtEdgeColo);
if(setLiterals != null && setLiterals.size() > 0 ){
//just for testing
if(mapRes.containsKey(dtEdgeColo)){
System.err.println("getMapDTEdgeColoursToLiterals has serious errors");
return null;
}

mapRes.put(dtEdgeColo, setLiterals);
}
}
}
}
return mapRes;
}

/**
* Get the map of data typed properties with the set of all associated literals
* @return
*/
public ObjectObjectOpenHashMap<BitSet, Set<String>> getMapDTEdgeColoursToLiterals(){
return mapDTEdgeColoursToLiterals;
}

/**
* get the map of data typed properties with the set of vertex IDs
* @return a map
*/
public ObjectObjectOpenHashMap<BitSet, IntSet> getMapDTEdgeColoursToVertexIDs(){
return mapDTEdgeColoursToVertexIDs;
}

public String getResourceURI(BitSet vColo){
return vertexPalette.getURI(vColo);
}
Expand All @@ -462,4 +388,59 @@ public String getDataTypedPropertyURI(BitSet dteColo){
return dtEdgePalette.getURI(dteColo);
}

public Map<BitSet, IntSet> getMapDTEdgeColoursToVertexIDs(){
Map<BitSet, IntSet> res =new HashMap<BitSet, IntSet>();
if(mapVertexIdAndLiterals != null && mapVertexIdAndLiterals.size() > 0 ){
IntSet setOfVIDs = getVertices();
int[] arrOfVIDs = setOfVIDs.toIntArray();

for(int vId: arrOfVIDs){
Map<BitSet, List<String>> mapDTEColoursToVIDs = mapVertexIdAndLiterals.get(vId);
if(mapDTEColoursToVIDs != null && mapDTEColoursToVIDs.size() > 0 ){
Set<BitSet> setOfDTEColours = mapDTEColoursToVIDs.keySet();

for(BitSet dteColo : setOfDTEColours){

IntSet setOfLinkedVIDs = res.get(dteColo);
if(setOfLinkedVIDs ==null){
setOfLinkedVIDs = new DefaultIntSet();
res.put(dteColo, setOfLinkedVIDs);
}
setOfLinkedVIDs.add(vId);
}
}
}
}
return res;
}

public Map<BitSet, List<String>> getMapDTEdgeColoursToLiterals(int vertexId){
if(mapVertexIdAndLiterals.containsKey(vertexId) ){
return mapVertexIdAndLiterals.get(vertexId);
}
return null;
}

public Map<BitSet, Set<String>> getMapDTEdgeColoursToLiterals(){
Map<BitSet, Set<String>> res = new HashMap<BitSet, Set<String>>();
Set<Integer> setOfVIDs = mapVertexIdAndLiterals.keySet();
for(Integer vId: setOfVIDs){
Map<BitSet, List<String>> mapDTEColoursToLiterals = mapVertexIdAndLiterals.get(vId);
Set<BitSet> setOfDTEColours = mapDTEColoursToLiterals.keySet();

for(BitSet dteColo: setOfDTEColours){
List<String> lstOfLiterals = mapDTEColoursToLiterals.get(dteColo);

Set<String> setOfAllLiterals = res.get(dteColo);
if(setOfAllLiterals == null){
setOfAllLiterals = new HashSet<String>();
res.put(dteColo, setOfAllLiterals);
}

setOfAllLiterals.addAll(lstOfLiterals);
}
}

return res;
}
}
Loading

0 comments on commit 2e96d42

Please sign in to comment.