codero 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codero-1.0.0/LICENSE +21 -0
- codero-1.0.0/PKG-INFO +29 -0
- codero-1.0.0/README +1 -0
- codero-1.0.0/codero/__init__.py +15 -0
- codero-1.0.0/codero/cli.py +60 -0
- codero-1.0.0/codero/decider.py +30 -0
- codero-1.0.0/codero/features/__init__.py +8 -0
- codero-1.0.0/codero/features/horizontal.py +49 -0
- codero-1.0.0/codero/features/result.py +30 -0
- codero-1.0.0/codero/features/text.py +49 -0
- codero-1.0.0/codero/finalize.py +50 -0
- codero-1.0.0/codero/loc.py +167 -0
- codero-1.0.0/codero/strategy/__init__.py +8 -0
- codero-1.0.0/codero/strategy/lines.py +170 -0
- codero-1.0.0/codero/strategy/text/__init__.py +140 -0
- codero-1.0.0/codero/strategy/text/numbers.py +187 -0
- codero-1.0.0/codero.egg-info/PKG-INFO +29 -0
- codero-1.0.0/codero.egg-info/SOURCES.txt +28 -0
- codero-1.0.0/codero.egg-info/dependency_links.txt +1 -0
- codero-1.0.0/codero.egg-info/entry_points.txt +2 -0
- codero-1.0.0/codero.egg-info/requires.txt +14 -0
- codero-1.0.0/codero.egg-info/top_level.txt +1 -0
- codero-1.0.0/pyproject.toml +104 -0
- codero-1.0.0/setup.cfg +4 -0
- codero-1.0.0/tests/test_cli.py +44 -0
- codero-1.0.0/tests/test_decider.py +32 -0
- codero-1.0.0/tests/test_lines.py +79 -0
- codero-1.0.0/tests/test_regression.py +27 -0
- codero-1.0.0/tests/test_text.py +109 -0
- codero-1.0.0/tests/test_validate.py +85 -0
codero-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Helmut Konrad Schewe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
codero-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codero
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Author-email: Helmut Konrad Schewe <helmutus@outlook.com>
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/anaticulae/codero
|
|
7
|
+
Project-URL: Repository, https://github.com/anaticulae/codero
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: utilo<3.0.0,>=2.109.1
|
|
15
|
+
Requires-Dist: iamraw<5.0.0,>=4.93.0
|
|
16
|
+
Requires-Dist: elementae<2.0.0,>=1.0.1
|
|
17
|
+
Requires-Dist: configos<2.0.0,>=1.0.4
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: gennex<2.0.0,>=1.1.0; extra == "dev"
|
|
20
|
+
Requires-Dist: groupmes<2.0.0,>=1.1.0; extra == "dev"
|
|
21
|
+
Requires-Dist: headnote<2.0.0,>=1.0.3; extra == "dev"
|
|
22
|
+
Requires-Dist: hoverpower<2.0.0,>=1.5.2; extra == "dev"
|
|
23
|
+
Requires-Dist: ibidem<2.0.0,>=1.0.2; extra == "dev"
|
|
24
|
+
Requires-Dist: mundare<2.0.0,>=1.0.2; extra == "dev"
|
|
25
|
+
Requires-Dist: pagenumber<2.0.0,>=1.0.0; extra == "dev"
|
|
26
|
+
Requires-Dist: utilotest<2.0.0,>=1.0.5; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# codero
|
codero-1.0.0/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# codero
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
#==============================================================================
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
__version__ = '0.6.3'
|
|
13
|
+
|
|
14
|
+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
15
|
+
PROCESS = 'codero'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import utilo
|
|
11
|
+
|
|
12
|
+
import codero
|
|
13
|
+
|
|
14
|
+
DESCRIPTION = 'TODO'
|
|
15
|
+
|
|
16
|
+
SOURCES = [
|
|
17
|
+
utilo.ResultFile('rawmaker', 'oneline_text_text'),
|
|
18
|
+
utilo.ResultFile('rawmaker', 'oneline_text_positions'),
|
|
19
|
+
utilo.ResultFile('rawmaker', 'oneline_fonts_header'),
|
|
20
|
+
utilo.ResultFile('rawmaker', 'oneline_fonts_content'),
|
|
21
|
+
utilo.ResultFile('rawmaker', 'border_pages'),
|
|
22
|
+
utilo.ResultFile('groupme', 'footer_footerheader'),
|
|
23
|
+
utilo.ResultFile('rawmaker', 'horizontals_horizontals'),
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
WORKPLAN = [
|
|
27
|
+
utilo.create_step(
|
|
28
|
+
'horizontal',
|
|
29
|
+
inputs=SOURCES,
|
|
30
|
+
output=('horizontal',),
|
|
31
|
+
),
|
|
32
|
+
utilo.create_step(
|
|
33
|
+
'text',
|
|
34
|
+
inputs=SOURCES,
|
|
35
|
+
output=('text',),
|
|
36
|
+
),
|
|
37
|
+
utilo.create_step(
|
|
38
|
+
'result',
|
|
39
|
+
inputs=[
|
|
40
|
+
utilo.ResultFile('codero', 'horizontal_horizontal'),
|
|
41
|
+
utilo.ResultFile('codero', 'text_text'),
|
|
42
|
+
],
|
|
43
|
+
output=('result',),
|
|
44
|
+
),
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def main():
|
|
49
|
+
utilo.featurepack(
|
|
50
|
+
root=codero.ROOT,
|
|
51
|
+
workplan=WORKPLAN,
|
|
52
|
+
featurepackage='codero.features',
|
|
53
|
+
config=utilo.FeaturePackConfig(
|
|
54
|
+
description=DESCRIPTION,
|
|
55
|
+
multiprocessed=True,
|
|
56
|
+
name=codero.PROCESS,
|
|
57
|
+
pages=True,
|
|
58
|
+
version=codero.__version__,
|
|
59
|
+
),
|
|
60
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import iamraw
|
|
11
|
+
import utilo
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def decide(horizontal, text):
|
|
15
|
+
data = (horizontal, text)
|
|
16
|
+
result = []
|
|
17
|
+
for pagenumber, (horizontalx, textx) in utilo.sync_pages(iterators=data,):
|
|
18
|
+
horizontalx = horizontalx.content if horizontalx else []
|
|
19
|
+
textx = textx.content if textx else []
|
|
20
|
+
best = horizontalx if score(horizontalx) > score(textx) else textx
|
|
21
|
+
result.append(iamraw.PageContent(content=best, page=pagenumber))
|
|
22
|
+
return result
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def score(items) -> int:
|
|
26
|
+
result = 0
|
|
27
|
+
for item in items:
|
|
28
|
+
result += len(item.caption)
|
|
29
|
+
result += len(item.tokens)
|
|
30
|
+
return result
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import serializeraw
|
|
11
|
+
|
|
12
|
+
import codero.finalize
|
|
13
|
+
import codero.strategy.lines
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def work(
|
|
17
|
+
oneline_text: str,
|
|
18
|
+
oneline_textposition: str,
|
|
19
|
+
oneline_font_header: str,
|
|
20
|
+
oneline_font_content: str,
|
|
21
|
+
sizeandborder: str,
|
|
22
|
+
headerfooter: str,
|
|
23
|
+
horizontalx: str,
|
|
24
|
+
pages: tuple = None,
|
|
25
|
+
) -> str:
|
|
26
|
+
ptcns = serializeraw.ptcn_fromfile(
|
|
27
|
+
oneline_text,
|
|
28
|
+
oneline_textposition,
|
|
29
|
+
sizeandborder,
|
|
30
|
+
headerfooter,
|
|
31
|
+
oneline_font_header,
|
|
32
|
+
oneline_font_content,
|
|
33
|
+
horizontals=horizontalx,
|
|
34
|
+
pages=pages,
|
|
35
|
+
)
|
|
36
|
+
parsed = run(ptcns)
|
|
37
|
+
dumped = serializeraw.dump_codes(parsed)
|
|
38
|
+
return dumped
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run(ptcns) -> list:
|
|
42
|
+
result = []
|
|
43
|
+
for ptn in ptcns:
|
|
44
|
+
parsed = codero.strategy.lines.parse(ptn)
|
|
45
|
+
if not parsed.content:
|
|
46
|
+
continue
|
|
47
|
+
result.append(parsed)
|
|
48
|
+
result = codero.finalize.run(result, ptcns)
|
|
49
|
+
return result
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import serializeraw
|
|
11
|
+
|
|
12
|
+
import codero.decider
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def work(
|
|
16
|
+
horizontalx: str,
|
|
17
|
+
textx: str,
|
|
18
|
+
pages: tuple = None,
|
|
19
|
+
) -> str:
|
|
20
|
+
horizontalx = serializeraw.load_codes(
|
|
21
|
+
horizontalx,
|
|
22
|
+
pages=pages,
|
|
23
|
+
)
|
|
24
|
+
textx = serializeraw.load_codes(
|
|
25
|
+
textx,
|
|
26
|
+
pages=pages,
|
|
27
|
+
)
|
|
28
|
+
result = codero.decider.decide(horizontalx, textx)
|
|
29
|
+
dumped = serializeraw.dump_codes(result)
|
|
30
|
+
return dumped
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import serializeraw
|
|
11
|
+
|
|
12
|
+
import codero.finalize
|
|
13
|
+
import codero.strategy.text
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def work(
|
|
17
|
+
oneline_text: str,
|
|
18
|
+
oneline_textposition: str,
|
|
19
|
+
oneline_font_header: str,
|
|
20
|
+
oneline_font_content: str,
|
|
21
|
+
sizeandborder: str,
|
|
22
|
+
headerfooter: str,
|
|
23
|
+
horizontalx: str,
|
|
24
|
+
pages: tuple = None,
|
|
25
|
+
) -> str:
|
|
26
|
+
ptcns = serializeraw.ptcn_fromfile(
|
|
27
|
+
oneline_text,
|
|
28
|
+
oneline_textposition,
|
|
29
|
+
sizeandborder,
|
|
30
|
+
headerfooter,
|
|
31
|
+
oneline_font_header,
|
|
32
|
+
oneline_font_content,
|
|
33
|
+
horizontals=horizontalx,
|
|
34
|
+
pages=pages,
|
|
35
|
+
)
|
|
36
|
+
parsed = run(ptcns)
|
|
37
|
+
dumped = serializeraw.dump_codes(parsed)
|
|
38
|
+
return dumped
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run(ptcns) -> list:
|
|
42
|
+
result = []
|
|
43
|
+
for ptn in ptcns:
|
|
44
|
+
parsed = codero.strategy.text.parse(ptn)
|
|
45
|
+
if not parsed.content:
|
|
46
|
+
continue
|
|
47
|
+
result.append(parsed)
|
|
48
|
+
result = codero.finalize.run(result, ptcns)
|
|
49
|
+
return result
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import iamraw
|
|
11
|
+
import texmex
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def run(codes: iamraw.PeaceOfCodes, ptns):
|
|
16
|
+
codes = insert_code_boundings(codes, ptns)
|
|
17
|
+
codes = horizontals_remove(codes, ptns)
|
|
18
|
+
return codes
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def insert_code_boundings(codes: iamraw.PeaceOfCodes, ptns):
|
|
22
|
+
for page in codes:
|
|
23
|
+
ptn = utilo.select_page(ptns, page=page.page)
|
|
24
|
+
for code in page.content:
|
|
25
|
+
for caption in code.caption:
|
|
26
|
+
code.caption_bounding.append(tuple(ptn[caption].bounding))
|
|
27
|
+
for token in code.tokens:
|
|
28
|
+
code.tokens_bounding.append(tuple(ptn[token].bounding))
|
|
29
|
+
return codes
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def horizontals_remove(codes: iamraw.PeaceOfCodes, ptns):
|
|
33
|
+
"""Adjust indexes of caption and token to ptns without horizontals."""
|
|
34
|
+
for page in codes:
|
|
35
|
+
ptn = utilo.select_page(ptns, page=page.page)
|
|
36
|
+
before = horizontals_before(ptn)
|
|
37
|
+
for code in page.content:
|
|
38
|
+
code.caption = {item - before[item] for item in code.caption}
|
|
39
|
+
code.tokens = {item - before[item] for item in code.tokens}
|
|
40
|
+
return codes
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def horizontals_before(ptn):
|
|
44
|
+
before = 0
|
|
45
|
+
result = []
|
|
46
|
+
for item in ptn:
|
|
47
|
+
result.append(before)
|
|
48
|
+
if item.text == texmex.HORIZONTAL:
|
|
49
|
+
before += 1
|
|
50
|
+
return result
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def determine(text: str) -> bool:
|
|
16
|
+
"""\
|
|
17
|
+
>>> determine('print("hello")')
|
|
18
|
+
True
|
|
19
|
+
"""
|
|
20
|
+
text = text.lower().strip()
|
|
21
|
+
methods = [
|
|
22
|
+
isjs,
|
|
23
|
+
ispython,
|
|
24
|
+
isbash,
|
|
25
|
+
isobjectc,
|
|
26
|
+
]
|
|
27
|
+
if any(method(text) for method in methods):
|
|
28
|
+
return True
|
|
29
|
+
return False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def prepare(keys, left=r'\b', right=r'\b', escape: bool = False):
|
|
33
|
+
if escape:
|
|
34
|
+
keys = (re.escape(item) for item in keys)
|
|
35
|
+
items = [left + item + right for item in keys]
|
|
36
|
+
result = utilo.compiles('(' + '|'.join(items) + ')')
|
|
37
|
+
return result
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
PYTHON_KEYWORDS = utilo.splititems("""assert async await break continue
|
|
41
|
+
del elif else except finally for global if lambda pass raise nonlocal
|
|
42
|
+
return try while yield yield from as with import""")
|
|
43
|
+
PYTHON_KEYWORDS = prepare(PYTHON_KEYWORDS)
|
|
44
|
+
PYTHON_METHODS = utilo.splititems("""
|
|
45
|
+
__import__ abs all any bin bool bytearray bytes chr classmethod compile
|
|
46
|
+
complex delattr dict dir divmod enumerate eval filter float format
|
|
47
|
+
frozenset getattr globals hasattr hash hex id input int isinstance
|
|
48
|
+
issubclass iter len list locals map max memoryview min next object oct
|
|
49
|
+
open ord pow print property range repr reversed round set setattr slice
|
|
50
|
+
sorted staticmethod str sum super tuple namedtuple
|
|
51
|
+
""")
|
|
52
|
+
PYTHON_METHODS = prepare(PYTHON_METHODS, right='\\(')
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def ispython(text: str) -> bool:
|
|
56
|
+
"""\
|
|
57
|
+
>>> ispython('Abc = collections.namedtuple("Abc a b c")')
|
|
58
|
+
True
|
|
59
|
+
"""
|
|
60
|
+
if PYTHON_KEYWORDS.search(text):
|
|
61
|
+
return True
|
|
62
|
+
if PYTHON_METHODS.search(text):
|
|
63
|
+
return True
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
JAVASCRIPT_KEYWORDS = utilo.splitlines("""for own in of while until loop
|
|
68
|
+
break return continue switch when then if unless else throw try catch
|
|
69
|
+
finally new delete typeof instanceof super true false yes no on off null
|
|
70
|
+
NaN Infinity undefined void val map apply length split sum""")
|
|
71
|
+
JAVASCRIPT_KEYWORDS = prepare(JAVASCRIPT_KEYWORDS)
|
|
72
|
+
# .reduce(
|
|
73
|
+
JAVASCRIPT_METHODS = utilo.compiles(r'\.[a-z]{3,15}\(')
|
|
74
|
+
JAVASCRIPT_START = utilo.splititems("""// /** /* * ) } )} val""")
|
|
75
|
+
JAVASCRIPT_START = prepare(
|
|
76
|
+
keys=JAVASCRIPT_START,
|
|
77
|
+
left=r'^',
|
|
78
|
+
right='',
|
|
79
|
+
escape=True,
|
|
80
|
+
)
|
|
81
|
+
# 2 val tfidf
|
|
82
|
+
JAVASCRIPT_ASSIGNMENT = utilo.compiles(r"""
|
|
83
|
+
^
|
|
84
|
+
(var|val)
|
|
85
|
+
[ ]{0,3}
|
|
86
|
+
\w[\w\d]{1,40}
|
|
87
|
+
[\:\=]
|
|
88
|
+
""")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def isjs(text: str) -> bool:
|
|
92
|
+
"""\
|
|
93
|
+
>>> isjs('.reduce((vector1, vector2) =>')
|
|
94
|
+
True
|
|
95
|
+
>>> isjs('}')
|
|
96
|
+
True
|
|
97
|
+
>>> isjs('var tfidf:')
|
|
98
|
+
True
|
|
99
|
+
>>> isjs('val tfidf=230')
|
|
100
|
+
True
|
|
101
|
+
"""
|
|
102
|
+
if JAVASCRIPT_KEYWORDS.search(text):
|
|
103
|
+
return True
|
|
104
|
+
if JAVASCRIPT_METHODS.search(text):
|
|
105
|
+
return True
|
|
106
|
+
if JAVASCRIPT_START.search(text):
|
|
107
|
+
return True
|
|
108
|
+
if JAVASCRIPT_ASSIGNMENT.match(text):
|
|
109
|
+
return True
|
|
110
|
+
return False
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
BASH_KEYWORDS = utilo.splititems("""for do done in while screen quit ssh
|
|
114
|
+
#/bin/bash bin bash .sh csp scp
|
|
115
|
+
""")
|
|
116
|
+
BASH_KEYWORDS = prepare(BASH_KEYWORDS, escape=True)
|
|
117
|
+
BASH_ASSIGNMENT = utilo.compiles(r"""
|
|
118
|
+
^
|
|
119
|
+
[\w|\_]{1,30}
|
|
120
|
+
\=
|
|
121
|
+
["'‘]
|
|
122
|
+
""")
|
|
123
|
+
BASH_COMMENT = utilo.compiles(r"""
|
|
124
|
+
^
|
|
125
|
+
\#{1,4}[ ]
|
|
126
|
+
""")
|
|
127
|
+
BASH_VAR = utilo.compiles(r"""
|
|
128
|
+
[$]
|
|
129
|
+
(
|
|
130
|
+
\d|
|
|
131
|
+
\w{1,10}
|
|
132
|
+
)
|
|
133
|
+
""")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def isbash(text: str) -> bool:
|
|
137
|
+
"""\
|
|
138
|
+
>>> isbash('#/bin/bash')
|
|
139
|
+
True
|
|
140
|
+
"""
|
|
141
|
+
if BASH_KEYWORDS.search(text):
|
|
142
|
+
return True
|
|
143
|
+
if BASH_ASSIGNMENT.search(text):
|
|
144
|
+
return True
|
|
145
|
+
if BASH_COMMENT.search(text):
|
|
146
|
+
return True
|
|
147
|
+
if BASH_VAR.search(text):
|
|
148
|
+
return True
|
|
149
|
+
return False
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
OBJECTC_START = utilo.splititems("""// /** /* * ) } )} ...""")
|
|
153
|
+
OBJECTC_START = prepare(OBJECTC_START, escape=True)
|
|
154
|
+
OBJECTC_KEYWORDS = utilo.splititems("""target << |= [[""")
|
|
155
|
+
OBJECTC_KEYWORDS = prepare(OBJECTC_KEYWORDS, escape=True)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def isobjectc(text: str) -> bool:
|
|
159
|
+
"""\
|
|
160
|
+
>>> isobjectc('t.target_addr |= [[ target objectForKey:@"main"] intValue] << 11; ')
|
|
161
|
+
True
|
|
162
|
+
"""
|
|
163
|
+
if OBJECTC_START.search(text):
|
|
164
|
+
return True
|
|
165
|
+
if OBJECTC_KEYWORDS.search(text):
|
|
166
|
+
return True
|
|
167
|
+
return False
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|