Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Upload on Pypi

on:
release:
types: [published]

permissions:
contents: read

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with unittest
run: |
python3 -m unittest tests/tests.py

release-build:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Build release distributions
run: |
# NOTE: put your own distribution build steps here.
python -m pip install build
python -m build

- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/

pypi-publish:
needs: release-build
name: Publish package distributions to TestPyPI
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://pypi.org/project/corpus-query-language
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Télécharger les artefacts du build
uses: actions/download-artifact@v4 # <-- Ajoutez cette étape
with:
name: release-dists # <-- Nom de l'artefact uploadé dans `release-build`
path: dist/
# retrieve your distributions here
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
name: Python application

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

permissions:
contents: read

jobs:
build:

Test-code:
runs-on: ubuntu-latest

steps:
Expand Down
30 changes: 27 additions & 3 deletions .github/workflows/testpypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Upload Python Package
name: Upload on test.pypi

on:
push:
Expand All @@ -17,7 +17,31 @@ permissions:
contents: read

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with unittest
run: |
python3 -m unittest tests/tests.py

release-build:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand All @@ -44,7 +68,7 @@ jobs:
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/CQLEngine
url: https://test.pypi.org/p/corpus-query-language
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
Expand All @@ -57,4 +81,4 @@ jobs:
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/p/CQLEngine
repository-url: https://test.pypi.org/legacy/
26 changes: 26 additions & 0 deletions CQL.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Python package project: CQL (Corpus Query Language) parser:
# - parsing of any kind of annotation: word, lemma, pos, morph
# - combination of annotations: [lemma='rey' & pos='NCMP000']
# - one or zero annotations [lemma='rey']?.
# - distance [lemma='rey'][]{,5}[lemma='santo']
# - any regex in the annotation value [lemma='reye?s?']
# - alternatives: [lemma='rey']|[lemma='príncipe'][]{,5}[lemma='santo']
import sys
import CQLEngine.functions as functions

# Takes a list of dicts with the annotations as input. Returns:
# - a list of spans (search_all function)
# - a boolean (match function)



def main():
query = sys.argv[1]
corpus = functions.import_corpus("tests/test_data/test_corpus.json")
MyEngine = functions.CQLEngine()
MyEngine.findall(corpus, query)
MyEngine.match(corpus, query)


if __name__ == '__main__':
main()
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "CQLEngine"
name = "corpus-query-language"
version = "0.0.1"
authors = [
{ name="Matthias Gille Levenson", email="matthias.gille-levenson@ens-lyon.fr" },
Expand All @@ -13,6 +13,13 @@ classifiers = [
]
license = " CC-BY-NC-SA-4.0"
license-files = ["LICEN[CS]E*"]
dependencies = [
"ply"
]

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project.urls]
Homepage = "https://github.com/matgille/CQL"
Expand Down
69 changes: 0 additions & 69 deletions src/CQLEngine/CQL.py

This file was deleted.

44 changes: 25 additions & 19 deletions src/CQLEngine/engine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import src.CQLEngine.functions as functions
import CQLEngine.functions as functions

def parse_corpus(ast, corpus, debug, match=True):

def parse_corpus(ast, corpus, mode, debug):
match = False
text_end = False
tree_index = 0
text_index = 0

Expand All @@ -20,45 +22,49 @@ def parse_corpus(ast, corpus, debug, match=True):
analysis_list = ['lemma', 'pos', 'morph', 'word']

# Text-directed engine.
while match == False:
if debug:
print("-")
print(corpus[text_index])
print(f"Text index: {text_index}")
print(f"Tree index: {tree_index}")
print(f"Ast length: {ast_length}")
while text_end == False:

# On teste si on est en bout de texte.
if len(corpus) == text_index:
if debug:
print("End of text. Exiting.")
break
if text_index + 1 == len(corpus):
tree_index += 1
if len(corpus) == text_index and tree_index != ast_length:
if debug:
print("End of text. Exiting.")
print("End of text a. Exiting.")
text_end = True
if mode == "match":
return False
break


# Si on matche la longueur de notre arbre
if tree_index == ast_length:
match = True
all_spans.append((first_matching_index, text_index))
first_matching_index = None
if match is True:
return True
if debug:
print(f"Appending {(first_matching_index, text_index)} to spans.")
print(tree_index)
print(ast_length)
first_matching_index = None
if match is True and mode == "match":
return True
text_index += 1
tree_index = 0
matches = True
# La boucle s'arrête là

if debug:
print("-")
print(corpus[text_index])
print(f"Text index: {text_index}")
print(f"Tree index: {tree_index}")
print(f"Ast length: {ast_length}")
current_query = ast[tree_index]
operator = current_query[0]
if debug:
print(f"Current query: {current_query}")
if operator in analysis_list:
if debug:
print(f"{operator} in list of analysis")
print(len(corpus))
print(text_index)
if functions.simple_match(current_query, corpus[text_index]):
if debug:
print("Found you a. Going forward on tree and text.")
Expand Down
Loading