mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
(qs, WIP) Clean up dead code
This commit is contained in:
parent
98a1adbf81
commit
dc65b2ee01
@ -10,7 +10,8 @@ import java.util.stream.Stream;
|
|||||||
* with a single start node and a single end node, denoted by QWord.beg() and QWord.end() respectively.
|
* with a single start node and a single end node, denoted by QWord.beg() and QWord.end() respectively.
|
||||||
* <p></p>
|
* <p></p>
|
||||||
* Naively, every path from the start to the end node should represent a valid query variant, although in
|
* Naively, every path from the start to the end node should represent a valid query variant, although in
|
||||||
* practice it is desirable to be clever about how to evaluate the paths, to avoid combinatorial explosion.
|
* practice it is desirable to be clever about how to evaluate the paths, to avoid a large number of queries
|
||||||
|
* being generated.
|
||||||
*/
|
*/
|
||||||
public class QWordGraph implements Iterable<QWord> {
|
public class QWordGraph implements Iterable<QWord> {
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ public class QWordGraph implements Iterable<QWord> {
|
|||||||
public List<QWordGraphLink> links() {
|
public List<QWordGraphLink> links() {
|
||||||
return Collections.unmodifiableList(links);
|
return Collections.unmodifiableList(links);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<QWord> nodes() {
|
public List<QWord> nodes() {
|
||||||
return links.stream()
|
return links.stream()
|
||||||
.flatMap(l -> Stream.of(l.from(), l.to()))
|
.flatMap(l -> Stream.of(l.from(), l.to()))
|
||||||
@ -120,39 +122,6 @@ public class QWordGraph implements Iterable<QWord> {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if removing the word would disconnect the graph
|
|
||||||
// so that there is no path from 'begin' to 'end'. This is useful
|
|
||||||
// in breaking up the graph into smaller component subgraphs, and
|
|
||||||
// understanding which vertexes can be re-ordered without changing
|
|
||||||
// the semantics of the encoded query.
|
|
||||||
public boolean isBypassed(QWord word, QWord begin, QWord end) {
|
|
||||||
Set<QWord> edge = new HashSet<>();
|
|
||||||
Set<QWord> visited = new HashSet<>();
|
|
||||||
|
|
||||||
edge.add(begin);
|
|
||||||
|
|
||||||
while (!edge.isEmpty()) {
|
|
||||||
Set<QWord> next = new HashSet<>();
|
|
||||||
|
|
||||||
for (var w : edge) {
|
|
||||||
// Skip the word we're trying find a bypassing route for
|
|
||||||
if (w.ord() == word.ord())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (Objects.equals(w, end))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
next.addAll(getNext(w));
|
|
||||||
}
|
|
||||||
|
|
||||||
next.removeAll(visited);
|
|
||||||
visited.addAll(next);
|
|
||||||
edge = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<QWord, Set<QWord>> forwardReachability() {
|
public Map<QWord, Set<QWord>> forwardReachability() {
|
||||||
Map<QWord, Set<QWord>> ret = new HashMap<>();
|
Map<QWord, Set<QWord>> ret = new HashMap<>();
|
||||||
|
|
||||||
|
@ -9,40 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
|
|
||||||
class QWordGraphTest {
|
class QWordGraphTest {
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddConstructor() {
|
|
||||||
QWordGraph graph = new QWordGraph("hello", "world");
|
|
||||||
|
|
||||||
System.out.println(graph.isBypassed(graph.nodes().get(1), QWord.beg(), QWord.end()));
|
|
||||||
System.out.println(graph.isBypassed(graph.nodes().get(2), QWord.beg(), QWord.end()));
|
|
||||||
System.out.println(graph.compileToQuery());
|
|
||||||
graph.forwardReachability().entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().ord())).forEach(System.out::println);
|
|
||||||
graph.links().forEach(System.out::println);
|
|
||||||
System.out.println("--");
|
|
||||||
graph.nodes().forEach(System.out::println);
|
|
||||||
System.out.println("--");
|
|
||||||
graph.addVariant(graph.nodes().get(1), "sup");
|
|
||||||
System.out.println(graph.compileToQuery());
|
|
||||||
graph.forwardReachability().entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().ord())).forEach(System.out::println);
|
|
||||||
System.out.println(graph.isBypassed(graph.nodes().get(1), QWord.beg(), QWord.end()));
|
|
||||||
System.out.println(graph.isBypassed(graph.nodes().get(2), QWord.beg(), QWord.end()));
|
|
||||||
System.out.println("--");
|
|
||||||
graph.links().forEach(System.out::println);
|
|
||||||
System.out.println("--");
|
|
||||||
graph.nodes().forEach(System.out::println);
|
|
||||||
|
|
||||||
graph.addVariantForSpan(graph.nodes().get(1), graph.nodes().get(2), "heyall");
|
|
||||||
graph.addVariant(graph.nodes().get(2), "globe");
|
|
||||||
System.out.println(graph.compileToQuery());
|
|
||||||
System.out.println(graph.isBypassed(graph.nodes().get(1), QWord.beg(), QWord.end()));
|
|
||||||
System.out.println(graph.isBypassed(graph.nodes().get(2), QWord.beg(), QWord.end()));
|
|
||||||
System.out.println("--");
|
|
||||||
graph.links().forEach(System.out::println);
|
|
||||||
System.out.println("--");
|
|
||||||
graph.nodes().forEach(System.out::println);
|
|
||||||
graph.forwardReachability().entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().ord())).forEach(System.out::println);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void forwardReachability() {
|
void forwardReachability() {
|
||||||
// Construct a graph like
|
// Construct a graph like
|
||||||
|
Loading…
Reference in New Issue
Block a user