Skip to content

Commit

Permalink
Merge pull request #86 from pm-osc/jg-1.1
Browse files Browse the repository at this point in the history
support for JanusGraph 1.1.0; added text predicates; version bump of dependencies
  • Loading branch information
FlorianHockmann authored Dec 19, 2024
2 parents 56dc2c1 + 5cedbd0 commit b1c71c7
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 54 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ of JanusGraph-Python:
| JanusGraph-Python | JanusGraph |
| ----------------- | ---------------------- |
| 1.0.z | 1.0.z |
| 1.1.z | (1.0.z,) 1.1.z |

While it should also be possible to use JanusGraph-Python with other versions of
JanusGraph than mentioned here, compatibility is not tested and some
Expand Down
91 changes: 91 additions & 0 deletions janusgraph_python/process/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ def text_contains(*args):
"""
return _JanusGraphP("textContains", *args)

@staticmethod
def text_not_contains(*args):
"""
Is true if no words inside the text string match the query string.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotContains", *args)

@staticmethod
def text_contains_prefix(*args):
"""
Expand All @@ -56,6 +66,16 @@ def text_contains_prefix(*args):
"""
return _JanusGraphP("textContainsPrefix", *args)

@staticmethod
def text_not_contains_prefix(*args):
"""
Is true if no words inside the text string begin with the query string.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotContainsPrefix", *args)

@staticmethod
def text_contains_regex(*args):
"""
Expand All @@ -66,6 +86,16 @@ def text_contains_regex(*args):
"""
return _JanusGraphP("textContainsRegex", *args)

@staticmethod
def text_not_contains_regex(*args):
"""
Is true if no words inside the text string match the given regular expression.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotContainsRegex", *args)

@staticmethod
def text_contains_fuzzy(*args):
"""
Expand All @@ -77,6 +107,37 @@ def text_contains_fuzzy(*args):
"""
return _JanusGraphP("textContainsFuzzy", *args)

@staticmethod
def text_not_contains_fuzzy(*args):
"""
Is true if no words inside the text string are similar to the query string
(based on Levenshtein edit distance).
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotContainsFuzzy", *args)

@staticmethod
def text_contains_phrase(*args):
"""
Is true if the text string does contain the sequence of words in the query string.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textContainsPhrase", *args)

@staticmethod
def text_not_contains_phrase(*args):
"""
Is true if the text string does not contain the sequence of words in the query string.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotContainsPhrase", *args)

@staticmethod
def text_prefix(*args):
"""
Expand All @@ -87,6 +148,16 @@ def text_prefix(*args):
"""
return _JanusGraphP("textPrefix", *args)

@staticmethod
def text_not_prefix(*args):
"""
Is true if the string value does not start with the given query string.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotPrefix", *args)

@staticmethod
def text_regex(*args):
"""
Expand All @@ -97,6 +168,16 @@ def text_regex(*args):
"""
return _JanusGraphP("textRegex", *args)

@staticmethod
def text_not_regex(*args):
"""
Is true if the string value does not match the given regular expression in its entirety.
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotRegex", *args)

@staticmethod
def text_fuzzy(*args):
"""
Expand All @@ -107,6 +188,16 @@ def text_fuzzy(*args):
"""
return _JanusGraphP("textFuzzy", *args)

@staticmethod
def text_not_fuzzy(*args):
"""
Is true if the string value is not similar to the given query string (based on Levenshtein edit distance).
:param query: string, The query to search.
:return The text predicate.
"""
return _JanusGraphP("textNotFuzzy", *args)

class RelationIdentifier(object):
_TO_STRING_DELIMITER = '-'

Expand Down
7 changes: 1 addition & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
aiohttp==3.10.10

# on Python 3.11 and 3.12 this is not installed automatically as dependency of aiohttp
async-timeout==4.0.3

gremlinpython==3.7.2
gremlinpython==3.7.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def read_requirements(path):

setup(
name='janusgraphpython',
version='1.0.0',
version='1.1.0',
description='JanusGraph-Python extends Apache TinkerPop™''s Gremlin-Python with support for JanusGraph-specific types.',
long_description=(this_directory/'README.md').read_text(),
long_description_content_type='text/markdown',
Expand Down
118 changes: 117 additions & 1 deletion tests/integration/Text_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_text_contains_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_contains(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('loves', 1),
param('shouldNotBeFound', 3),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_contains_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_not_contains(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
Expand All @@ -42,6 +54,19 @@ def test_text_contains_prefix_given_search_text(self, search_text, expected_coun
count = self.g.E().has('reason', Text.text_contains_prefix(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('wave', 2),
param('f', 1),
param('shouldNotBeFound', 3),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_contains_not_prefix_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_not_contains_prefix(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
Expand All @@ -54,6 +79,19 @@ def test_text_contains_regex_given_search_text(self, search_text, expected_count
count = self.g.E().has('reason', Text.text_contains_regex(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('.*ave.*', 2),
param('f.{3,4}', 1),
param('shouldNotBeFound', 3),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_contains_regex_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_not_contains_regex(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
Expand All @@ -65,6 +103,46 @@ def test_text_contains_fuzzy_given_search_text(self, search_text, expected_count
count = self.g.E().has('reason', Text.text_contains_fuzzy(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('waxes', 2),
param('shouldNotBeFound', 3),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_contains_fuzzy_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_not_contains_fuzzy(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('fresh breezes', 1),
param('no fear', 1),
param('fear of', 1),
param('should not be found', 0),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_contains_phrase_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_contains_phrase(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('fresh breezes', 2),
param('no fear', 2),
param('fear of', 2),
param('should not be found', 3),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_contains_phrase_given_search_text(self, search_text, expected_count):
count = self.g.E().has('reason', Text.text_not_contains_phrase(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
Expand All @@ -77,6 +155,19 @@ def test_text_prefix_given_search_text(self, search_text, expected_count):
count = self.g.V().has('name', Text.text_prefix(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('herc', 11),
param('s', 9),
param('shouldNotBeFound', 12),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_prefix_given_search_text(self, search_text, expected_count):
count = self.g.V().has('name', Text.text_not_prefix(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
Expand All @@ -89,6 +180,19 @@ def test_text_regex_given_search_text(self, search_text, expected_count):
count = self.g.V().has('name', Text.text_regex(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
param('.*rcule.*', 11),
param('s.{2}', 10),
param('shouldNotBeFound', 12),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_regex_given_search_text(self, search_text, expected_count):
count = self.g.V().has('name', Text.text_not_regex(search_text)).count().next()
assert count == expected_count

@mark.parametrize(
'search_text,expected_count',
[
Expand All @@ -100,4 +204,16 @@ def test_text_regex_given_search_text(self, search_text, expected_count):
def test_text_fuzzy_given_search_text(self, search_text, expected_count):
count = self.g.V().has('name', Text.text_fuzzy(search_text)).count().next()
assert count == expected_count


@mark.parametrize(
'search_text,expected_count',
[
param('herculex', 11),
param('ska', 10),
param('shouldNotBeFound', 12),
]
)
@mark.minimum_janusgraph_version("1.1.0")
def test_text_not_fuzzy_given_search_text(self, search_text, expected_count):
count = self.g.V().has('name', Text.text_not_fuzzy(search_text)).count().next()
assert count == expected_count
2 changes: 0 additions & 2 deletions tests/integration/config.ini

This file was deleted.

4 changes: 4 additions & 0 deletions tests/integration/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dockerRepository": "janusgraph/janusgraph",
"dockerTags": ["1.0.1", "1.1.0"]
}
Loading

0 comments on commit b1c71c7

Please sign in to comment.