Close gaping hole due to O(n!) algorithm (lol).
This commit is contained in:
parent
32b57bd849
commit
a96cf45bfa
1 changed files with 6 additions and 2 deletions
|
@ -65,11 +65,15 @@ class Graph:
|
||||||
# Return an empty.
|
# Return an empty.
|
||||||
return Node(uri)
|
return Node(uri)
|
||||||
|
|
||||||
def existing_permutations(self, uri):
|
def existing_permutations(self, uri, max_length=4):
|
||||||
# looks up nodes matching a permutation of the tokenized uri.
|
# looks up nodes matching a permutation of the tokenized uri.
|
||||||
#
|
#
|
||||||
# example use: if [[server-agora]] does not exist, serve [[agora-server]]
|
# example use: if [[server-agora]] does not exist, serve [[agora-server]]
|
||||||
permutations = itertools.permutations(uri.split('-'))
|
#
|
||||||
|
# this is, of course, a terrible implementation and dangerous :)
|
||||||
|
# only enable up to 4 tokens as 24 permutations is manageable.
|
||||||
|
tokens = uri.split('-')
|
||||||
|
permutations = itertools.permutations(tokens, max_length)
|
||||||
permutations = ['-'.join(permutation) for permutation in permutations]
|
permutations = ['-'.join(permutation) for permutation in permutations]
|
||||||
nodes = [node for node in G.nodes() if node.wikilink in permutations and node.subnodes]
|
nodes = [node for node in G.nodes() if node.wikilink in permutations and node.subnodes]
|
||||||
return nodes
|
return nodes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue