forked from pool/python-nltk
Daniel Garcia
9adfbd9e5d
(CVE-2024-39705, gh#nltk/nltk#3266, bsc#1227174). - Drop CVE-2024-39705-disable-download.patch as it's not needed anymore. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-nltk?expand=0&rev=49
111 lines
3.6 KiB
Diff
111 lines
3.6 KiB
Diff
From 25d35fc4283dedd2053ec6d821f4b707fff8d72c Mon Sep 17 00:00:00 2001
|
|
From: Konstantin Chernyshev <k4black@ya.ru>
|
|
Date: Thu, 16 Nov 2023 19:00:15 +0100
|
|
Subject: [PATCH 1/8] ci: enable 3.12 in ci tests
|
|
|
|
---
|
|
.github/workflows/ci.yaml | 2 +-
|
|
README.md | 2 +-
|
|
nltk/test/unit/translate/test_bleu.py | 1 -
|
|
nltk/translate/bleu_score.py | 29 +++++++++++++++++++++++++++--
|
|
setup.py | 3 ++-
|
|
5 files changed, 31 insertions(+), 6 deletions(-)
|
|
|
|
--- a/.github/workflows/ci.yaml
|
|
+++ b/.github/workflows/ci.yaml
|
|
@@ -76,7 +76,7 @@ jobs:
|
|
needs: [cache_nltk_data, cache_third_party]
|
|
strategy:
|
|
matrix:
|
|
- python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
|
|
+ python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
fail-fast: false
|
|
runs-on: ${{ matrix.os }}
|
|
--- a/README.md
|
|
+++ b/README.md
|
|
@@ -4,7 +4,7 @@
|
|
|
|
NLTK -- the Natural Language Toolkit -- is a suite of open source Python
|
|
modules, data sets, and tutorials supporting research and development in Natural
|
|
-Language Processing. NLTK requires Python version 3.7, 3.8, 3.9, 3.10 or 3.11.
|
|
+Language Processing. NLTK requires Python version 3.7, 3.8, 3.9, 3.10, 3.11 or 3.12.
|
|
|
|
For documentation, please visit [nltk.org](https://www.nltk.org/).
|
|
|
|
--- a/nltk/test/unit/translate/test_bleu.py
|
|
+++ b/nltk/test/unit/translate/test_bleu.py
|
|
@@ -2,7 +2,6 @@
|
|
Tests for BLEU translation evaluation metric
|
|
"""
|
|
|
|
-import io
|
|
import unittest
|
|
|
|
from nltk.data import find
|
|
--- a/nltk/translate/bleu_score.py
|
|
+++ b/nltk/translate/bleu_score.py
|
|
@@ -7,16 +7,41 @@
|
|
# For license information, see LICENSE.TXT
|
|
|
|
"""BLEU score implementation."""
|
|
-
|
|
import math
|
|
import sys
|
|
import warnings
|
|
from collections import Counter
|
|
-from fractions import Fraction
|
|
+from fractions import Fraction as _Fraction
|
|
|
|
from nltk.util import ngrams
|
|
|
|
|
|
+class Fraction(_Fraction):
|
|
+ """Fraction with _normalize=False support for 3.12"""
|
|
+
|
|
+ def __new__(cls, numerator=0, denominator=None, _normalize=False):
|
|
+ if sys.version_info >= (3, 12):
|
|
+ self = super().__new__(cls, numerator, denominator)
|
|
+ else:
|
|
+ self = super().__new__(cls, numerator, denominator, _normalize=_normalize)
|
|
+ self._normalize = _normalize
|
|
+ self._original_numerator = numerator
|
|
+ self._original_denominator = denominator
|
|
+ return self
|
|
+
|
|
+ @property
|
|
+ def numerator(self):
|
|
+ if not self._normalize:
|
|
+ return self._original_numerator
|
|
+ return super().numerator
|
|
+
|
|
+ @property
|
|
+ def denominator(self):
|
|
+ if not self._normalize:
|
|
+ return self._original_denominator
|
|
+ return super().denominator
|
|
+
|
|
+
|
|
def sentence_bleu(
|
|
references,
|
|
hypothesis,
|
|
--- a/setup.py
|
|
+++ b/setup.py
|
|
@@ -67,7 +67,7 @@ setup(
|
|
},
|
|
long_description="""\
|
|
The Natural Language Toolkit (NLTK) is a Python package for
|
|
-natural language processing. NLTK requires Python 3.7, 3.8, 3.9, 3.10 or 3.11.""",
|
|
+natural language processing. NLTK requires Python 3.7, 3.8, 3.9, 3.10, 3.11 or 3.12.""",
|
|
license="Apache License, Version 2.0",
|
|
keywords=[
|
|
"NLP",
|
|
@@ -100,6 +100,7 @@ natural language processing. NLTK requi
|
|
"Programming Language :: Python :: 3.9",
|
|
"Programming Language :: Python :: 3.10",
|
|
"Programming Language :: Python :: 3.11",
|
|
+ "Programming Language :: Python :: 3.12",
|
|
"Topic :: Scientific/Engineering",
|
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
"Topic :: Scientific/Engineering :: Human Machine Interfaces",
|