engtagger 0.4.5 → 0.4.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be5e5dcb477d743356b79d58eadb358a4bd1a47e2b318011313ea46a577402f9
4
- data.tar.gz: c8c0fa1024e6d2ad2bb3d619eb92b259f7fe25076ad82119345c5ceab192af45
3
+ metadata.gz: 61101478ee5332b3ba91df6598db0e4822832be62edaf5ac8613256d8ba8d7d4
4
+ data.tar.gz: 903c665fd059b5095f2f240c2522f2a593d92bbf8cb500b142f6af373d48802c
5
5
  SHA512:
6
- metadata.gz: 2cd4aa320c5c01fa830b68163c8a0b88acc5a87eb91e6ccc2880adb033d6d291be75542867efc7fe8610257cb4cafd61714abaff59f1cb674e07ae5e38820be3
7
- data.tar.gz: 5ad319a0decea08e49b1b68022d86d0b9e856524bbaa684fe518199139f7cfd7e708d218910780ec052a633b685f8a9bb68876b7b3c27f87da446d5d06f3b434
6
+ metadata.gz: 066d0510e7a585c38273a4fb28f33e05f9eb6f64a340b22ca3a6e05e8946866b769dc1966fc729f5351d16a318e6f6d2c41f4929a2bc627ad9d384654ba3a85f
7
+ data.tar.gz: d19da0ed3236dcc64963cb64fe5a7833b3c3790433c9b4dee06c87e2abb2cdf30733cdf55a6b9409396096c0f95e383d47a8cd168f7fda954874c544646227d8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.6 (2026-11-14)
4
+
5
+ - Fix `get_noun_phrases`, `get_words` and `add_tags` taking time quadratic in
6
+ the input length on long runs of nouns and on long texts. Output is
7
+ unchanged. Upgrade if you tag text from untrusted sources.
8
+
3
9
  ## 0.4.5 (2026-08-14)
4
10
 
5
11
  License metadata correction; no code changes. This library is a port (2009) of
data/Rakefile CHANGED
@@ -18,3 +18,8 @@ task :normalize_permissions do
18
18
  end
19
19
 
20
20
  Rake::Task["build"].enhance([:normalize_permissions])
21
+
22
+ # Pre-release gate: after building, open the .gem and verify its payload
23
+ # against spec.files in both directions, then scan names, contents and modes.
24
+ # `rake release` depends on `build`, so a FAIL here stops the push.
25
+ Rake::Task["build"].enhance { sh "ruby", "scripts/verify_gem.rb" }
data/engtagger.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.license = "GPL-3.0-only"
12
12
  gem.required_ruby_version = Gem::Requirement.new(">= 2.6")
13
13
  gem.files = Dir.chdir(File.expand_path(__dir__)) do
14
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|tools|docs)/}) }
14
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|tools|docs|scripts)/}) }
15
15
  end
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
17
  gem.name = "engtagger"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class EngTagger
4
- VERSION = "0.4.5"
4
+ VERSION = "0.4.6"
5
5
  end
data/lib/engtagger.rb CHANGED
@@ -545,23 +545,27 @@ class EngTagger
545
545
 
546
546
  found = Hash.new(0)
547
547
  phrase_ext = /(?:#{PREP}|#{DET}|#{NUM})+/xo
548
+ noun = /#{NN}/o
549
+ longest = @conf[:longest_noun_phrase]
548
550
  scanned = tagged.scan(@@mnp)
549
551
  # Find MNPs in the text, one sentence at a time
550
552
  # Record and split if the phrase is extended by a (?:PREP|DET|NUM)
551
553
  mn_phrases = []
552
554
  scanned.each do |m|
553
555
  found[m] += 1 if phrase_ext =~ m
554
- mn_phrases += m.split(phrase_ext)
556
+ mn_phrases.concat(m.split(phrase_ext))
555
557
  end
556
558
  mn_phrases.each do |mnp|
557
559
  # Split the phrase into an array of words, and create a loop for each word,
558
560
  # shortening the phrase by removing the word in the first position.
559
561
  # Record the phrase and any single nouns that are found
560
562
  words = mnp.split
561
- words.length.times do
562
- found[words.join(" ")] += 1 if words.length > 1
563
- w = words.shift
564
- found[w] += 1 if w =~ /#{NN}/
563
+ words.each_index do |i|
564
+ # Longer phrases would be dropped by the length limit below, so they
565
+ # are not built in the first place.
566
+ length = words.length - i
567
+ found[words[i..].join(" ")] += 1 if length > 1 && length <= longest
568
+ found[words[i]] += 1 if noun.match?(words[i])
565
569
  end
566
570
  end
567
571
  ret = Hash.new(0)
@@ -677,7 +681,7 @@ class EngTagger
677
681
  tokenized = []
678
682
  # Tokenize the text (splitting on punctuation as you go)
679
683
  cleaned_text.split(/\s+/).each do |line|
680
- tokenized += split_punct(line)
684
+ tokenized.concat(split_punct(line))
681
685
  end
682
686
  split_sentences(tokenized)
683
687
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engtagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.6.9
83
+ rubygems_version: 4.0.24
84
84
  specification_version: 4
85
85
  summary: A probability based, corpus-trained English POS tagger
86
86
  test_files: []