generated from QubitPi/jersey-webservice-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support 2 types of expand - apoc & plain BFS
- Loading branch information
Showing
9 changed files
with
471 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
target/ | ||
logback/ | ||
.DS_Store | ||
jetty-base/ | ||
jetty-home-11.0.15/ | ||
application.properties | ||
jetty-home-11.0.15.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
set -x | ||
set -e | ||
|
||
# Copyright Jiaqi Liu | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
mvn clean package -Dcheckstyle.skip -DskipTests | ||
|
||
wget -O jetty-home-11.0.15.tar.gz https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/11.0.15/jetty-home-11.0.15.tar.gz | ||
tar -xzvf jetty-home-11.0.15.tar.gz | ||
export JETTY_HOME=$(pwd)/jetty-home-11.0.15 | ||
|
||
mkdir -p jetty-base | ||
cd jetty-base | ||
java -jar $JETTY_HOME/start.jar --add-module=annotations,server,http,deploy,servlet,webapp,resources,jsp | ||
|
||
mv ../target/wilhelm-ws-1.0-SNAPSHOT.war webapps/ROOT.war | ||
java -jar $JETTY_HOME/start.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright Jiaqi Liu | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.qubitpi.wilhelm; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* A JSON-serializable object representation of a knowledge graph in wilhelm-ws. | ||
*/ | ||
public class Graph { | ||
|
||
private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); | ||
|
||
private final Set<Node> nodes; | ||
private final Set<Link> links; | ||
|
||
/** | ||
* All-args constructor. | ||
* | ||
* @param nodes | ||
* @param links | ||
*/ | ||
public Graph(final Set<Node> nodes, final Set<Link> links) { | ||
this.nodes = nodes; | ||
this.links = links; | ||
} | ||
|
||
public static Graph emptyGraph() { | ||
return new Graph(Collections.emptySet(), Collections.emptySet()); | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isEmpty() { | ||
return getNodes().isEmpty() && getLinks().isEmpty(); | ||
} | ||
|
||
public List<Node> getUndirectedNeighborsOf(Node node) { | ||
final Set<String> neighborIds = getLinks().stream() | ||
.filter(link -> node.getId().equals(link.getSourceNodeId()) || node.getId().equals(link.getTargetNodeId())) | ||
.flatMap(link -> Stream.of(link.getSourceNodeId(), link.getTargetNodeId())) | ||
.filter(id -> !node.getId().equals(id)) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
|
||
return getNodes().stream() | ||
.filter(it -> neighborIds.contains(it.getId())) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
public Graph merge(final Graph that) { | ||
return new Graph( | ||
Stream.of(this.getNodes(), that.getNodes()).flatMap(Set::stream).collect(Collectors.toSet()), | ||
Stream.of(this.getLinks(), that.getLinks()).flatMap(Set::stream).collect(Collectors.toSet()) | ||
); | ||
} | ||
|
||
public Set<Node> getNodes() { | ||
return nodes; | ||
} | ||
|
||
public Set<Link> getLinks() { | ||
return links; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
try { | ||
return JSON_MAPPER.writeValueAsString(this); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright Jiaqi Liu | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.qubitpi.wilhelm; | ||
|
||
import org.neo4j.driver.types.Relationship; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class Link { | ||
|
||
private final String label; | ||
private final String sourceNodeId; | ||
private final String targetNodeId; | ||
private final Map<String, Object> attributes; | ||
|
||
public Link( | ||
@NotNull final String label, | ||
@NotNull final String sourceNodeId, | ||
@NotNull final String targetNodeId, | ||
@NotNull final Map<String, Object> attributes | ||
) { | ||
this.label = label; | ||
this.sourceNodeId = sourceNodeId; | ||
this.targetNodeId = targetNodeId; | ||
this.attributes = attributes; | ||
} | ||
|
||
public static Link valueOf(Relationship relationship) { | ||
final String label = relationship.asMap().get("name").toString(); | ||
final Map<String, Object> attributes = relationship.asMap().entrySet().stream() | ||
.filter(entry -> !"name".equals(entry.getKey())) | ||
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
||
return new Link(label, relationship.startNodeElementId(), relationship.endNodeElementId(), attributes); | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public String getSourceNodeId() { | ||
return sourceNodeId; | ||
} | ||
|
||
public String getTargetNodeId() { | ||
return targetNodeId; | ||
} | ||
|
||
public Map<String, Object> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
final Link that = (Link) other; | ||
return Objects.equals(getLabel(), that.getLabel()) && Objects.equals( | ||
getSourceNodeId(), | ||
that.getSourceNodeId() | ||
) && Objects.equals( | ||
getTargetNodeId(), | ||
that.getTargetNodeId() | ||
) && Objects.equals(getAttributes(), that.getAttributes()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getLabel(), getSourceNodeId(), getTargetNodeId(), getAttributes()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("(%s)-%s-(%s)", getSourceNodeId(), getLabel(), getTargetNodeId()); | ||
} | ||
} |
Oops, something went wrong.