Skip to content

Commit f5fbef3

Browse files
committed
Set window length constant
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent 9ddf620 commit f5fbef3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/matchcode_toolkit/fingerprinting.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
import binascii
1111
import re
1212

13-
from samecode.halohash import BitAverageHaloHash
1413
from licensedcode.tokenize import query_lines
15-
14+
from samecode.halohash import BitAverageHaloHash
1615

1716
# A collection of directory fingerprints that we want to avoid
1817
IGNORED_DIRECTORY_FINGERPRINTS = [
@@ -21,6 +20,8 @@
2120
"0000000000000000000000000000000000000000",
2221
]
2322

23+
SNIPPET_WINDOW_LENGTH = 16
24+
2425

2526
def _create_directory_fingerprint(inputs):
2627
"""
@@ -166,6 +167,7 @@ def create_halohash_chunks(bah128):
166167
query_pattern = "[^_\\W]+"
167168
word_splitter = re.compile(query_pattern, re.UNICODE).findall
168169

170+
169171
# TODO: return line numbers from where the token was taken
170172
def _tokenizer(text):
171173
"""
@@ -197,7 +199,7 @@ def tokenizer(text):
197199

198200

199201
def get_file_fingerprint_hashes(
200-
location, ngram_length=5, window_length=16, include_ngrams=False, **kwargs
202+
location, ngram_length=5, window_length=SNIPPET_WINDOW_LENGTH, include_ngrams=False, **kwargs
201203
):
202204
"""
203205
Return a mapping of fingerprint hashes for the file at `location`
@@ -229,7 +231,9 @@ def get_file_fingerprint_hashes(
229231
)
230232

231233

232-
def create_file_fingerprints(content, ngram_length=5, window_length=16, include_ngrams=False):
234+
def create_file_fingerprints(
235+
content, ngram_length=5, window_length=SNIPPET_WINDOW_LENGTH, include_ngrams=False
236+
):
233237
"""
234238
Return a mapping of halo1 and snippet hashes from content string
235239
"""

0 commit comments

Comments
 (0)