Skip to content

Commit

Permalink
Make the 'USED BY' field say more accurately where used in Stanford NLP.
Browse files Browse the repository at this point in the history
  • Loading branch information
manning authored and Stanford NLP committed May 2, 2016
1 parent 94cb44e commit d7f0bd2
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 155 deletions.
32 changes: 13 additions & 19 deletions liblocal/README
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,32 @@ DESCRIPTION: ANTLR runtime, for compiled software

URL: http:https://www.antlr.com

USED BY:
The Quickcheck library
USED BY: The Quickcheck library (not directly used in Stanford NLP code)

LAST UPDATE: 2015/10/5

LAST UPDATE BY: Keenon Werling

-----------------------------------------------------------------------
java-hamcrest.jar
hamcrest-core.jar

ORIGINAL JAR NAME: java-hamcrest-2.0.0.0.jar
ORIGINAL JAR NAME: hamcrest-core-1.3.jar

VERSION: 2.0.0.0
VERSION: 1.3

RELEASE DATE: January 2015
RELEASE DATE: Jul, 2010

SOURCE AVAILABLE: Maven Central

DESCRIPTION: Hamcrest shennanigans, for JUnit

URL: http:https://www.hamcrest.org

USED BY:
The JUnit library
USED BY: The JUnit library (not directly used in Stanford NLP code)

LAST UPDATE: 2016-04-30
LAST UPDATE: 2015/10/5

LAST UPDATE BY: John Bauer
LAST UPDATE BY: Keenon Werling

-----------------------------------------------------------------------
javaruntype.jar
Expand All @@ -57,8 +55,7 @@ DESCRIPTION: Something for Quickcheck

URL: http:https://www.javaruntype.org

USED BY:
The Quickcheck library
USED BY: The Quickcheck library (not directly used in Stanford NLP code)

LAST UPDATE: 2015/10/5

Expand All @@ -79,8 +76,7 @@ DESCRIPTION: Quickcheck, runs random inputs and validates outputs

URL: https://github.com/pholser/junit-quickcheck

USED BY:
The Quickcheck library
USED BY: loglinear package tests

LAST UPDATE: 2015/10/5

Expand All @@ -97,7 +93,7 @@ RELEASE DATE: Nov, 2013

SOURCE AVAILABLE: Maven Central

DESCRIPTION: Quickcheck, runs random inputs and validates outputs
DESCRIPTION: loglinear package tests

URL: https://github.com/pholser/junit-quickcheck

Expand All @@ -123,8 +119,7 @@ DESCRIPTION: JUnit theories run JUnit against a number of inputs

URL: junit.org

USED BY:
The Quickcheck library
USED BY: loglinear package tests

LAST UPDATE: 2015/10/5

Expand All @@ -145,8 +140,7 @@ DESCRIPTION: Object graph navigation library, used by Quickcheck

URL: https://commons.apache.org/proper/commons-ognl/

USED BY:
The Quickcheck library
USED BY: The Quickcheck library (not directly used in Stanford NLP code)

LAST UPDATE: 2015/10/5

Expand Down
Binary file added liblocal/hamcrest-core.jar
Binary file not shown.
Binary file removed liblocal/java-hamcrest.jar
Binary file not shown.
Binary file removed libsrc/java-hamcrest-sources.jar
Binary file not shown.
153 changes: 50 additions & 103 deletions src/edu/stanford/nlp/graph/DirectedMultiGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import edu.stanford.nlp.semgraph.SemanticGraphEdge;
import edu.stanford.nlp.util.CollectionUtils;
import edu.stanford.nlp.util.Generics;
import edu.stanford.nlp.util.MapFactory;
Expand Down Expand Up @@ -40,9 +41,8 @@ public DirectedMultiGraph(MapFactory<V, Map<V, List<E>>> outerMapFactory, MapFac
}

/**
* Creates a copy of the given graph. This will copy the entire data
* structure (this may be slow!), but will not copy any of the edge
* or vertex objects.
* Creates a copy of the given graph. This will copy the entire data structure (this may be slow!), but will not copy
* any of the edge or vertex objects.
*
* @param graph The graph to copy into this object.
*/
Expand Down Expand Up @@ -477,38 +477,39 @@ public List<Set<V>> getConnectedComponents() {
/**
* Deletes all duplicate edges.
*/
public void deleteDuplicateEdges() {
for (V vertex : getAllVertices()) {
for (V vertex2 : outgoingEdges.get(vertex).keySet()) {
List<E> data = outgoingEdges.get(vertex).get(vertex2);
Set<E> deduplicatedData = new TreeSet<>(data);
data.clear();
data.addAll(deduplicatedData);
}
for (V vertex2 : incomingEdges.get(vertex).keySet()) {
List<E> data = incomingEdges.get(vertex).get(vertex2);
Set<E> deduplicatedData = new TreeSet<>(data);
data.clear();
data.addAll(deduplicatedData);
}
}
}

public void deleteDuplicateEdges() {
for (V vertex : getAllVertices()) {
for (V vertex2 : outgoingEdges.get(vertex).keySet()) {
List<E> data = outgoingEdges.get(vertex).get(vertex2);
Set<E> deduplicatedData = new TreeSet<>(data);
data.clear();
data.addAll(deduplicatedData);
}
for (V vertex2 : incomingEdges.get(vertex).keySet()) {
List<E> data = incomingEdges.get(vertex).get(vertex2);
Set<E> deduplicatedData = new TreeSet<>(data);
data.clear();
data.addAll(deduplicatedData);
}
}
}


public Iterator<E> incomingEdgeIterator(final V vertex) {
return new EdgeIterator<>(vertex, incomingEdges, outgoingEdges);
return new EdgeIterator<>(incomingEdges, vertex);
}

public Iterable<E> incomingEdgeIterable(final V vertex) {
return () -> new EdgeIterator<>(vertex, incomingEdges, outgoingEdges);
return () -> new EdgeIterator<>(incomingEdges, vertex);
}

public Iterator<E> outgoingEdgeIterator(final V vertex) {
return new EdgeIterator<>(vertex, outgoingEdges, incomingEdges);
return new EdgeIterator<>(outgoingEdges, vertex);
}

public Iterable<E> outgoingEdgeIterable(final V vertex) {
return () -> new EdgeIterator<>(vertex, outgoingEdges, incomingEdges);
return () -> new EdgeIterator<>(outgoingEdges, vertex);
}

public Iterator<E> edgeIterator() {
Expand All @@ -519,40 +520,28 @@ public Iterable<E> edgeIterable() {
return () -> new EdgeIterator<>(DirectedMultiGraph.this);
}


/**
* This class handles either iterating over a single vertex's
* connections or over all connections in a graph.
*/

static class EdgeIterator<V, E> implements Iterator<E> {
private final Map<V, Map<V, List<E>>> reverseEdges;
/** when iterating over the whole graph, this iterates over nodes */
private Iterator<Map.Entry<V, Map<V, List<E>>>> vertexIterator;
/** for a given node, this iterates over its neighbors */
private Iterator<Map.Entry<V, List<E>>> connectionIterator;
/** given the neighbor of a node, this iterates over all its connections */
private final Map<V, Map<V, List<E>>> incomingEdges;
private Iterator<Map<V, List<E>>> vertexIterator;
private Iterator<List<E>> connectionIterator;
private Iterator<E> edgeIterator;

private V currentSource = null;
private V currentTarget = null;
private E currentEdge = null;
private E lastRemoved = null;
private boolean hasNext = true;


public EdgeIterator(DirectedMultiGraph<V, E> graph) {
vertexIterator = graph.outgoingEdges.entrySet().iterator();
reverseEdges = graph.incomingEdges;
vertexIterator = graph.outgoingEdges.values().iterator();
incomingEdges = graph.incomingEdges;
}

public EdgeIterator(V startVertex, Map<V, Map<V, List<E>>> source,
Map<V, Map<V, List<E>>> reverseEdges) {
currentSource = startVertex;
public EdgeIterator(Map<V, Map<V, List<E>>> source, V startVertex) {
Map<V, List<E>> neighbors = source.get(startVertex);
if (neighbors != null) {
vertexIterator = null;
connectionIterator = neighbors.entrySet().iterator();
connectionIterator = neighbors.values().iterator();
}
this.reverseEdges = reverseEdges;
incomingEdges = null;
}

@Override
Expand All @@ -566,22 +555,18 @@ public E next() {
if (!hasNext()) {
throw new NoSuchElementException("Graph edge iterator exhausted.");
}
currentEdge = edgeIterator.next();
return currentEdge;
lastRemoved = edgeIterator.next();
return lastRemoved;
}

private void primeIterator() {
if (edgeIterator != null && edgeIterator.hasNext()) {
hasNext = true; // technically, we shouldn't need to put this here, but let's be safe
} else if (connectionIterator != null && connectionIterator.hasNext()) {
Map.Entry<V, List<E>> nextConnection = connectionIterator.next();
edgeIterator = nextConnection.getValue().iterator();
currentTarget = nextConnection.getKey();
edgeIterator = connectionIterator.next().iterator();
primeIterator();
} else if (vertexIterator != null && vertexIterator.hasNext()) {
Map.Entry<V, Map<V, List<E>>> nextVertex = vertexIterator.next();
connectionIterator = nextVertex.getValue().entrySet().iterator();
currentSource = nextVertex.getKey();
connectionIterator = vertexIterator.next().values().iterator();
primeIterator();
} else {
hasNext = false;
Expand All @@ -590,60 +575,22 @@ private void primeIterator() {

@Override
public void remove() {
if (currentEdge != null) {
reverseEdges.get(currentTarget).get(currentSource).remove(currentEdge);
edgeIterator.remove();

if (reverseEdges.get(currentTarget).get(currentSource) != null &&
reverseEdges.get(currentTarget).get(currentSource).size() == 0) {
connectionIterator.remove();
reverseEdges.get(currentTarget).remove(currentSource);
// TODO: may not be necessary to set this to null
edgeIterator = null;
}
if (incomingEdges == null) {
throw new UnsupportedOperationException("remove() is only valid if iterating over entire graph (Gabor was too lazy to implement the general case...sorry!)");
}
}
}

/**
* Topological sort of the graph.
* <br>
* This method uses the depth-first search implementation of
* topological sort.
* Topological sorting only works if the graph is acyclic.
*
* @return A sorted list of the vertices
* @throws IllegalStateException if this graph is not a DAG
*/
public List<V> topologicalSort() {
List<V> result = Generics.newArrayList();
Set<V> temporary = outerMapFactory.newSet();
Set<V> permanent = outerMapFactory.newSet();
for (V vertex : getAllVertices()) {
if (!temporary.contains(vertex)) {
topologicalSortHelper(vertex, temporary, permanent, result);
}
}
Collections.reverse(result);
return result;
}

private void topologicalSortHelper(V vertex, Set<V> temporary, Set<V> permanent, List<V> result) {
temporary.add(vertex);
Map<V, List<E>> neighborMap = outgoingEdges.get(vertex);
if (neighborMap != null) {
for (V neighbor : neighborMap.keySet()) {
if (permanent.contains(neighbor)) {
continue;
}
if (temporary.contains(neighbor)) {
throw new IllegalStateException("This graph has cycles. Topological sort not possible: " + this.toString());
if (lastRemoved != null) {
if (lastRemoved instanceof SemanticGraphEdge) {
SemanticGraphEdge edge = (SemanticGraphEdge) lastRemoved;
//noinspection unchecked
incomingEdges.get((V) edge.getDependent()).get((V) edge.getGovernor()).remove((E) edge);
edgeIterator.remove();
} else {
// TODO(from gabor): This passes the tests, but actually leaves the graph in an inconsistent state.
edgeIterator.remove();
// throw new UnsupportedOperationException("remove() is only valid if iterating over semantic graph edges (Gabor was too lazy to implement the general case...sorry!)");
}
topologicalSortHelper(neighbor, temporary, permanent, result);
}
}
result.add(vertex);
permanent.add(vertex);
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/edu/stanford/nlp/pipeline/demo/corenlp-brat.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Takes Stanford CoreNLP JSON output (var data = ... in data.js)
// and uses brat to render everything.

//var serverAddress = 'http:https://localhost:9000';
//var serverAddress = 'http:https://corenlp.run';
var serverAddress = '';
//var serverAddress = 'http:https://localhost:9000/'
var serverAddress = 'http:https://corenlp.run'

// Load Brat libraries
var bratLocation = 'https://storage.googleapis.com/corenlp/js/brat';
Expand Down Expand Up @@ -121,7 +120,7 @@ function nerColor(nerTag) {
*/
function annotators() {
var annotators = "tokenize,ssplit"
$('#annotators').find('option:selected').each(function () {
$('#annotators option:selected').each(function () {
annotators += "," + $(this).val();
});
return annotators;
Expand Down Expand Up @@ -669,7 +668,7 @@ function renderSemgrex(data) {
*/
$(document).ready(function() {
// Some initial styling
$('.chosen-select').chosen();
$(".chosen-select").chosen();
$('.chosen-container').css('width', '100%');

// Submit on shift-enter
Expand Down Expand Up @@ -795,7 +794,7 @@ $(document).ready(function() {
// Make ajax call
$.ajax({
type: 'POST',
url: serverAddress + '/tokensregex?pattern=' + encodeURIComponent(pattern.replace("&", "\\&").replace('+', '\\+')),
url: serverAddress + 'tokensregex?pattern=' + encodeURIComponent(pattern.replace("&", "\\&").replace('+', '\\+')),
data: currentQuery,
success: function(data) {
$('.tokensregex_error').remove(); // Clear error messages
Expand Down Expand Up @@ -827,7 +826,7 @@ $(document).ready(function() {
// Make ajax call
$.ajax({
type: 'POST',
url: serverAddress + '/semgrex?pattern=' + encodeURIComponent(pattern.replace("&", "\\&").replace('+', '\\+')),
url: serverAddress + 'semgrex?pattern=' + encodeURIComponent(pattern.replace("&", "\\&").replace('+', '\\+')),
data: currentQuery,
success: function(data) {
$('.semgrex_error').remove(); // Clear error messages
Expand Down
Loading

0 comments on commit d7f0bd2

Please sign in to comment.