Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkapoor committed Aug 19, 2014
2 parents df3114b + 376e7cc commit aa609f0
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public UpdateContainer doIt(Workspace workspace) throws CommandException {
}
}

if(domainUriOrId.endsWith(" (add)"))
domainUriOrId = domainUriOrId.substring(0, domainUriOrId.length()-5).trim();

domain = alignment.getNodeById(domainUriOrId);
logger.info("Got domain for domainUriOrId:" + domainUriOrId + " ::" + domain);
if (domain == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONObject;

import edu.isi.karma.controller.update.AbstractUpdate;
import edu.isi.karma.controller.update.ErrorUpdate;
import edu.isi.karma.controller.update.InfoUpdate;
import edu.isi.karma.controller.update.UpdateContainer;
import edu.isi.karma.rep.Workspace;
Expand Down Expand Up @@ -50,23 +51,30 @@ public CommandType getCommandType() {

@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
ServletContextParameterMap.setParameterValue(ContextParameter.USER_DIRECTORY_PATH, directory);
Preferences preferences = Preferences.userRoot().node("WebKarma");
preferences.put("KARMA_USER_HOME", directory);

UpdateContainer uc = new UpdateContainer();
uc.add(new InfoUpdate("Successfully changed Karma Home Directory"));
uc.add(new AbstractUpdate() {

@Override
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject obj = new JSONObject();
obj.put(GenericJsonKeys.updateType.name(), "ReloadPageUpdate");
pw.println(obj.toString());
}

File dir = new File(directory);
if(dir.exists()) {
ServletContextParameterMap.setParameterValue(ContextParameter.USER_DIRECTORY_PATH, directory);
Preferences preferences = Preferences.userRoot().node("WebKarma");
preferences.put("KARMA_USER_HOME", directory);

});

uc.add(new InfoUpdate("Successfully changed Karma Home Directory"));
uc.add(new AbstractUpdate() {

@Override
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject obj = new JSONObject();
obj.put(GenericJsonKeys.updateType.name(), "ReloadPageUpdate");
pw.println(obj.toString());
}

});
} else {
uc.add(new ErrorUpdate("Karma home could not be changed. The specified directory does not exist"));
}
return uc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ public boolean addNodeAndUpdate(Node node, Set<Node> addedNodes) {

// updateLinksFromThing();

long updateLinksFromThing = System.currentTimeMillis();
elapsedTimeSec = (updateLinksFromThing - updateLinks)/1000F;
logger.debug("time to update links to Thing (root): " + elapsedTimeSec);
// long updateLinksFromThing = System.currentTimeMillis();
// elapsedTimeSec = (updateLinksFromThing - updateLinks)/1000F;
// logger.debug("time to update links to Thing (root): " + elapsedTimeSec);

logger.debug("total number of nodes in graph: " + this.graph.vertexSet().size());
logger.debug("total number of links in graph: " + this.graph.edgeSet().size());
Expand Down Expand Up @@ -779,12 +779,12 @@ private void initialGraph() {
logger.debug("<enter");

// Add Thing to the Graph
if (!ModelingConfiguration.getManualAlignment()) {
String id = nodeIdFactory.getNodeId(Uris.THING_URI);
Label label = new Label(Uris.THING_URI, Namespaces.OWL, Prefixes.OWL);
Node thing = new InternalNode(id, label);
addNode(thing);
}
// if (!ModelingConfiguration.getManualAlignment()) {
// String id = nodeIdFactory.getNodeId(Uris.THING_URI);
// Label label = new Label(Uris.THING_URI, Namespaces.OWL, Prefixes.OWL);
// Node thing = new InternalNode(id, label);
// addNode(thing);
// }

logger.debug("exit>");
}
Expand Down Expand Up @@ -1163,6 +1163,7 @@ public static void main(String[] args) throws Exception {
File[] ontologies = ontDir.listFiles();
OntologyManager mgr = new OntologyManager();
for (File ontology: ontologies) {
System.out.println(ontology.getName());
if (ontology.getName().endsWith(".owl") ||
ontology.getName().endsWith(".rdf") ||
ontology.getName().endsWith(".n3") ||
Expand All @@ -1173,14 +1174,27 @@ public static void main(String[] args) throws Exception {
String encoding = EncodingDetector.detect(ontology);
mgr.doImport(ontology, encoding);
} catch (Exception t) {
logger.error ("Error loading ontology: " + ontology.getAbsolutePath(), t);
// logger.error("Error loading ontology: " + ontology.getAbsolutePath(), t);
}
} else {
logger.error ("the file: " + ontology.getAbsolutePath() + " does not have proper format: xml/rdf/n3/ttl/owl");
}
}
// update the cache at the end when all files are added to the model
mgr.updateCache();
Set<String> test = mgr.getPossibleUris("http://example.com/layout/C01_", "http://example.com/layout/C02_");
for (String s : test) {
System.out.println(s);
}
Alignment al = new Alignment(mgr);
ColumnNode c1 = al.addColumnNode("h1", "c1", null);
ColumnNode c2 = al.addColumnNode("h2", "c2", null);
InternalNode n1 = al.addInternalNode(new Label("http://example.com/layout/C01_"));
InternalNode n2 = al.addInternalNode(new Label("http://example.com/layout/C02_"));
al.addDataPropertyLink(n1, c1, new Label("http://example.com/layout/d1"), false);
al.addDataPropertyLink(n2, c2, new Label("http://example.com/layout/d2"), false);
al.align();
System.out.println(GraphUtil.labeledGraphToString(al.getSteinerTree()));
} else {
logger.info("No directory for preloading ontologies exists.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,44 @@ public static WeightedMultigraph<Node, LabeledLink> asLabeledGraph(WeightedMulti
return g;
}

public static void printLabeledGraph(Graph<Node, LabeledLink> graph) {

if (graph == null) {
logger.debug("graph is null.");
return;
}
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (DefaultLink link : graph.edgeSet()) {
sb.append(link.getId());
sb.append(", ");
sb.append(link.getType().toString());
sb.append(", ");
sb.append(link.getWeight());
sb.append("\n");
}
// sb.append("------------------------------------------");
logger.debug(sb.toString());
}

public static void printGraph(Graph<Node, DefaultLink> graph) {

if (graph == null) {
logger.debug("graph is null.");
return;
}
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***");
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***");
sb.append("*** Links ***\n");
for (DefaultLink link : graph.edgeSet()) {
sb.append(link.getId());
sb.append(", ");
Expand All @@ -198,7 +223,13 @@ public static String defaultGraphToString(Graph<Node, DefaultLink> graph) {
return "";
}

StringBuffer sb = new StringBuffer();
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (DefaultLink edge : graph.edgeSet()) {
sb.append("(");
sb.append(edge.getId());
Expand All @@ -218,6 +249,12 @@ public static String labeledGraphToString(Graph<Node, LabeledLink> graph) {
}

StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (LabeledLink edge : graph.edgeSet()) {
sb.append("(");
sb.append(edge.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

import edu.isi.karma.modeling.ModelingConfiguration;
import edu.isi.karma.modeling.Namespaces;
import edu.isi.karma.modeling.Prefixes;
import edu.isi.karma.modeling.Uris;
Expand Down Expand Up @@ -73,8 +74,8 @@ public class OntologyCache {
private HashSet<String> directSubClassCheck;
private HashSet<String> indirectSubClassCheck;
// List <subclass, superclass> pairs
private List<SubclassSuperclassPair> directSubclassSuperclassPairs;
private List<SubclassSuperclassPair> indirectSubclassSuperclassPairs;
// private List<SubclassSuperclassPair> directSubclassSuperclassPairs;
// private List<SubclassSuperclassPair> indirectSubclassSuperclassPairs;

// hashmap: class -> subproperties
private HashMap<String, HashMap<String, Label>> directSubProperties;
Expand Down Expand Up @@ -156,6 +157,12 @@ public void init() {
logger.info("number of properties explicitly defined as owl:DatatypeProperty:" + (properties.size() - objectProperties.size()) );
logger.info("number of properties explicitly defined as owl:ObjectProperty:" + (properties.size() - dataProperties.size()) );

if (ModelingConfiguration.getManualAlignment()) {
float elapsedTimeSec = (System.currentTimeMillis() - start)/1000F;
logger.info("time to build the ontology cache (manual alignment): " + elapsedTimeSec);
return;
}

// build hashmaps for indirect subclass and subproperty relationships
logger.info("build subclass hashmaps ...");
this.buildSubClassesMaps();
Expand Down Expand Up @@ -228,8 +235,8 @@ private void allocateDataStructures() {
this.indirectSuperClasses = new HashMap<String, HashMap<String, Label>>();
this.directSubClassCheck = new HashSet<String>();
this.indirectSubClassCheck = new HashSet<String>();
this.directSubclassSuperclassPairs = new ArrayList<SubclassSuperclassPair>();
this.indirectSubclassSuperclassPairs = new ArrayList<SubclassSuperclassPair>();
// this.directSubclassSuperclassPairs = new ArrayList<SubclassSuperclassPair>();
// this.indirectSubclassSuperclassPairs = new ArrayList<SubclassSuperclassPair>();

this.directSubProperties = new HashMap<String, HashMap<String, Label>>();
this.indirectSubProperties = new HashMap<String, HashMap<String, Label>>();
Expand Down Expand Up @@ -341,13 +348,13 @@ public HashSet<String> getIndirectSubClassCheck() {
return indirectSubClassCheck;
}

public List<SubclassSuperclassPair> getDirectSubclassSuperclassPairs() {
return directSubclassSuperclassPairs;
}

public List<SubclassSuperclassPair> getIndirectSubclassSuperclassPairs() {
return indirectSubclassSuperclassPairs;
}
// public List<SubclassSuperclassPair> getDirectSubclassSuperclassPairs() {
// return directSubclassSuperclassPairs;
// }
//
// public List<SubclassSuperclassPair> getIndirectSubclassSuperclassPairs() {
// return indirectSubclassSuperclassPairs;
// }

public HashMap<String, HashMap<String, Label>> getDirectSubProperties() {
return directSubProperties;
Expand Down Expand Up @@ -714,23 +721,21 @@ private void buildSubClassesMaps() {

for (String c : this.classes.keySet()) {

directSubClassesLocal = this.ontHandler.getSubClasses(c, false);
allSubClassesLocal = this.ontHandler.getSubClasses(c, true);
indirectSubClassesLocal = new HashMap<String, Label>();
for (Entry<String, Label> entry : allSubClassesLocal.entrySet())
if (!directSubClassesLocal.containsKey(entry.getKey()))
indirectSubClassesLocal.put(entry.getKey(), entry.getValue());

// Thing node
if (c.equalsIgnoreCase(Uris.THING_URI)) {
List<OntologyTreeNode> thingDirectChildren = this.classHierarchy.getChildren();
if (thingDirectChildren != null)
for (OntologyTreeNode node : thingDirectChildren)
if (node.getLabel() != null && node.getLabel().getUri() != null)
directSubClassesLocal.put(node.getLabel().getUri(), node.getLabel());

directSubClassesLocal = allClassesExceptThing;
indirectSubClassesLocal = allClassesExceptThing;
} else {

directSubClassesLocal = this.ontHandler.getSubClasses(c, false);
allSubClassesLocal = this.ontHandler.getSubClasses(c, true);
indirectSubClassesLocal = new HashMap<String, Label>();
for (Entry<String, Label> entry : allSubClassesLocal.entrySet())
if (!directSubClassesLocal.containsKey(entry.getKey()))
indirectSubClassesLocal.put(entry.getKey(), entry.getValue());

}


this.directSubClasses.put(c, directSubClassesLocal);
this.indirectSubClasses.put(c, indirectSubClassesLocal);
Expand All @@ -742,19 +747,19 @@ private void buildSubClassesMaps() {
this.indirectSubClassCheck.add(s + c);
}

for (String superclass : this.directSubClasses.keySet()) {
Set<String> subClasses = this.directSubClasses.get(superclass).keySet();
if (subClasses != null)
for (String subclass : subClasses)
this.directSubclassSuperclassPairs.add(new SubclassSuperclassPair(subclass, superclass));
}

for (String superclass : this.indirectSubClasses.keySet()) {
Set<String> subClasses = this.indirectSubClasses.get(superclass).keySet();
if (subClasses != null)
for (String subclass : subClasses)
this.indirectSubclassSuperclassPairs.add(new SubclassSuperclassPair(subclass, superclass));
}
// for (String superclass : this.directSubClasses.keySet()) {
// Set<String> subClasses = this.directSubClasses.get(superclass).keySet();
// if (subClasses != null)
// for (String subclass : subClasses)
// this.directSubclassSuperclassPairs.add(new SubclassSuperclassPair(subclass, superclass));
// }
//
// for (String superclass : this.indirectSubClasses.keySet()) {
// Set<String> subClasses = this.indirectSubClasses.get(superclass).keySet();
// if (subClasses != null)
// for (String subclass : subClasses)
// this.indirectSubclassSuperclassPairs.add(new SubclassSuperclassPair(subclass, superclass));
// }
}

private void buildSuperClassesMaps() {
Expand Down Expand Up @@ -1020,8 +1025,8 @@ private void buildObjectPropertiesMaps() {
}
directDomainsUris = ontHandler.getResourcesUris(directDomains);

if (directDomainsUris != null && directDomainsUris.contains(Uris.THING_URI))
directDomainsUris.remove(Uris.THING_URI);
// if (directDomainsUris != null && directDomainsUris.contains(Uris.THING_URI))
// directDomainsUris.remove(Uris.THING_URI);

temp = propertyDirectDomains.get(property.getURI());
if (temp == null)
Expand Down Expand Up @@ -1078,8 +1083,8 @@ private void buildObjectPropertiesMaps() {
}
directRangesUris = ontHandler.getResourcesUris(directRanges);

if (directRangesUris != null && directRangesUris.contains(Uris.THING_URI))
directRangesUris.remove(Uris.THING_URI);
// if (directRangesUris != null && directRangesUris.contains(Uris.THING_URI))
// directRangesUris.remove(Uris.THING_URI);

temp = propertyDirectRanges.get(property.getURI());
if (temp == null)
Expand Down Expand Up @@ -1499,8 +1504,10 @@ private void classifyProperties() {
else if (!haveDomain && haveRange) {
this.objectPropertiesWithOnlyRange.put(p, label);
}
else if (!haveDomain && !haveRange)
this.objectPropertiesWithoutDomainAndRange.put(p, label);
else if (!haveDomain && !haveRange) {
if (!p.startsWith(Namespaces.RDF) && !p.startsWith(Namespaces.RDFS))
this.objectPropertiesWithoutDomainAndRange.put(p, label);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public DisplayModel(DirectedWeightedMultigraph<Node, LabeledLink> model, HTable
public Set<LabeledLink> getOutgoingEdgesOf(Node node) {
Set<LabeledLink> edges = new HashSet<>();
for(DirectedWeightedMultigraph<Node, LabeledLink> model : models) {
edges.addAll(model.outgoingEdgesOf(node));
GraphUtil.printGraph(GraphUtil.asDefaultGraph(model));
if(model.containsVertex(node))
edges.addAll(model.outgoingEdgesOf(node));
}
return edges;
}
Expand Down
6 changes: 5 additions & 1 deletion karma-web/src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,12 @@ and related projects, please see: http://www.isi.edu/integration
$("#karmaHome").editable({
type: 'text',
success: function(response, newValue) {
var old = this.textContent;
console.log("Set Karma Home:" + newValue);
changeKarmaHome(newValue);
var success = changeKarmaHome(newValue);
if(!success) {
return old;
}
},
showbuttons: 'bottom',
mode: 'popup',
Expand Down
Loading

0 comments on commit aa609f0

Please sign in to comment.