-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_string.py
executable file
·44 lines (36 loc) · 1.43 KB
/
example_string.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/python3
# -----------------------------------------------------------------------------
# example_strings.py
#
# Author: ChatGPT-4 by OpenAI
# Contributor: Newton Winter
#
# This example file demonstrates the usage of libsais_wrapper.py for
# processing ASCII and Unicode strings. The primary author of the code
# is ChatGPT-4, an AI language model by OpenAI. Newton Winter provided
# the prompts, composition, and minor rearrangements.
# -----------------------------------------------------------------------------
import libsais_wrapper as lw
def string_to_ascii_list(s):
return [ord(c) for c in s]
def unicode_to_int64_list(u):
return [c for c in u.encode('utf-32-le')]
# ASCII string input
ascii_str = 'abbrashwabbrakadabbra'
T_ascii = string_to_ascii_list(ascii_str)
A_ascii = [0] * len(T_ascii)
n_ascii = len(T_ascii)
# Unicode string input (emoji)
unicode_str = '😀😁😂😃😄😅😆😀😁😂😃😀😁😂😀😁😃😄😅😆😂😃😄😅😆'
T_unicode = unicode_to_int64_list(unicode_str)
A_unicode = [0] * len(T_unicode)
n_unicode = len(T_unicode)
# Parameters
fs = 0
threads = 2
# ASCII example
result, A_ascii, _ = lw.libsais64(T_ascii, A_ascii, n_ascii, fs, threads=threads)
print("ASCII Example - libsais64: Suffix Array:", A_ascii)
# Unicode example
result, A_unicode, _ = lw.libsais64(T_unicode, A_unicode, n_unicode, fs, threads=threads)
print("Unicode Example - libsais64: Suffix Array:", A_unicode)