lindera 7.0.0 → 7.1.0
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 +4 -4
- data/Cargo.toml +25 -4
- data/src/dictionary.rs +1 -1
- data/src/token.rs +130 -2
- data/src/trainer.rs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d40b3b933702a34ad03024b41d0d1f91911d45bc7ff994d66096d75fce4d4fa
|
|
4
|
+
data.tar.gz: b28c49f195a93529b66b1bab2dd63ecfff89e3e6d238a80f7cbd49dca0d28b1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72748e122841af4f683305ce87bdb2551ca474ff64f97aeee1f952cd9daea1dfb711822ba8fcfeb5c931ebb2872519a3c67975db9b088a0a4ef426bc9a564afb
|
|
7
|
+
data.tar.gz: c13f56c94d4c7f4902a8c47bf792469a6347e0f835c044005aeda6a9b950dfce1532fbc6a2cba6b49d05150bb78c378d24cbc808b1c0f97f49afcc9ba59678f7
|
data/Cargo.toml
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
edition = "2024"
|
|
14
14
|
rust-version = "1.89"
|
|
15
15
|
name = "lindera-ruby"
|
|
16
|
-
version = "7.
|
|
16
|
+
version = "7.1.0"
|
|
17
17
|
build = false
|
|
18
18
|
publish = false
|
|
19
19
|
autolib = false
|
|
@@ -38,12 +38,33 @@ repository = "https://github.com/lindera/lindera"
|
|
|
38
38
|
resolver = "2"
|
|
39
39
|
|
|
40
40
|
[features]
|
|
41
|
-
default = [
|
|
41
|
+
default = [
|
|
42
|
+
"train",
|
|
43
|
+
"dependency",
|
|
44
|
+
]
|
|
45
|
+
dependency = ["lindera-binding/dependency"]
|
|
42
46
|
embed-cc-cedict = ["lindera/embed-cc-cedict"]
|
|
43
47
|
embed-cjk = ["lindera/embed-cjk"]
|
|
48
|
+
embed-dependency-ipadic = [
|
|
49
|
+
"dependency",
|
|
50
|
+
"lindera-binding/embed-dependency-ipadic",
|
|
51
|
+
]
|
|
52
|
+
embed-dependency-unidic = [
|
|
53
|
+
"dependency",
|
|
54
|
+
"lindera-binding/embed-dependency-unidic",
|
|
55
|
+
]
|
|
56
|
+
embed-dependency-unidic-csj = [
|
|
57
|
+
"dependency",
|
|
58
|
+
"lindera-binding/embed-dependency-unidic-csj",
|
|
59
|
+
]
|
|
60
|
+
embed-dependency-unidic-cwj = [
|
|
61
|
+
"dependency",
|
|
62
|
+
"lindera-binding/embed-dependency-unidic-cwj",
|
|
63
|
+
]
|
|
44
64
|
embed-ipadic = ["lindera/embed-ipadic"]
|
|
45
65
|
embed-ipadic-neologd = ["lindera/embed-ipadic-neologd"]
|
|
46
66
|
embed-jieba = ["lindera/embed-jieba"]
|
|
67
|
+
embed-jumandic = ["lindera/embed-jumandic"]
|
|
47
68
|
embed-ko-dic = ["lindera/embed-ko-dic"]
|
|
48
69
|
embed-sudachidict = ["lindera/embed-sudachidict"]
|
|
49
70
|
embed-unidic = ["lindera/embed-unidic"]
|
|
@@ -60,10 +81,10 @@ crate-type = [
|
|
|
60
81
|
path = "src/lib.rs"
|
|
61
82
|
|
|
62
83
|
[dependencies.lindera]
|
|
63
|
-
version = "=7.
|
|
84
|
+
version = "=7.1.0"
|
|
64
85
|
|
|
65
86
|
[dependencies.lindera-binding]
|
|
66
|
-
version = "=7.
|
|
87
|
+
version = "=7.1.0"
|
|
67
88
|
|
|
68
89
|
[dependencies.magnus]
|
|
69
90
|
version = "0.9.0"
|
data/src/dictionary.rs
CHANGED
|
@@ -190,7 +190,7 @@ fn load_user_dictionary_for(
|
|
|
190
190
|
/// * `metadata` - Metadata configuration for the dictionary.
|
|
191
191
|
/// * `context_id_freq:` - Path of a context-ID frequency histogram, such
|
|
192
192
|
/// as the `context_id_freq.txt` of a dictionary crate, as `lindera
|
|
193
|
-
/// build --context-id-freq` takes it. `nil` or omitted means none. Read
|
|
193
|
+
/// dictionary build --context-id-freq` takes it. `nil` or omitted means none. Read
|
|
194
194
|
/// only with `connection_id_mapping`.
|
|
195
195
|
///
|
|
196
196
|
/// # Returns
|
data/src/token.rs
CHANGED
|
@@ -12,6 +12,105 @@ use crate::util::integer_arg;
|
|
|
12
12
|
/// Token object wrapping the Rust Token data.
|
|
13
13
|
///
|
|
14
14
|
/// This class provides access to token fields and details.
|
|
15
|
+
/// The bunsetsu of a token and what that bunsetsu depends on: what the
|
|
16
|
+
/// token filter `japanese_dependency` writes on a token.
|
|
17
|
+
///
|
|
18
|
+
/// The bunsetsu of a sentence are numbered from 0, and each of them but the
|
|
19
|
+
/// last depends on a later one, its head.
|
|
20
|
+
#[derive(Clone)]
|
|
21
|
+
#[magnus::wrap(class = "Lindera::TokenDependency", free_immediately, size)]
|
|
22
|
+
pub struct RbTokenDependency {
|
|
23
|
+
/// The number of the sentence in the text, from 0.
|
|
24
|
+
sentence: u32,
|
|
25
|
+
/// The number of the bunsetsu of the token in its sentence, from 0.
|
|
26
|
+
bunsetsu: u32,
|
|
27
|
+
/// The number of the bunsetsu the bunsetsu of the token depends on.
|
|
28
|
+
head: Option<u32>,
|
|
29
|
+
/// What the token is in its bunsetsu.
|
|
30
|
+
role: &'static str,
|
|
31
|
+
/// The score of the decision that attached the bunsetsu to its head.
|
|
32
|
+
score: f64,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
impl RbTokenDependency {
|
|
36
|
+
/// Creates an `RbTokenDependency` from a lindera-binding
|
|
37
|
+
/// `DependencyView`.
|
|
38
|
+
///
|
|
39
|
+
/// # Arguments
|
|
40
|
+
///
|
|
41
|
+
/// * `view` - The dependency of a token view.
|
|
42
|
+
///
|
|
43
|
+
/// # Returns
|
|
44
|
+
///
|
|
45
|
+
/// A new `RbTokenDependency` instance.
|
|
46
|
+
fn from_view(view: lindera_binding::DependencyView) -> Self {
|
|
47
|
+
Self {
|
|
48
|
+
sentence: view.sentence,
|
|
49
|
+
bunsetsu: view.bunsetsu,
|
|
50
|
+
head: view.head,
|
|
51
|
+
role: view.role(),
|
|
52
|
+
score: view.score,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Returns the number of the sentence in the text, from 0.
|
|
57
|
+
fn sentence(&self) -> u32 {
|
|
58
|
+
self.sentence
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// Returns the number of the bunsetsu of the token in its sentence,
|
|
62
|
+
/// from 0.
|
|
63
|
+
fn bunsetsu(&self) -> u32 {
|
|
64
|
+
self.bunsetsu
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Returns the number of the bunsetsu that the bunsetsu of the token
|
|
68
|
+
/// depends on, or nil for the last bunsetsu of a sentence.
|
|
69
|
+
fn head(&self) -> Option<u32> {
|
|
70
|
+
self.head
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Returns what the token is in its bunsetsu: `head`, `function`,
|
|
74
|
+
/// `head_function` or `other`.
|
|
75
|
+
fn role(&self) -> &'static str {
|
|
76
|
+
self.role
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// Returns the score of the decision that attached the bunsetsu to its
|
|
80
|
+
/// head; 0 where there was nothing to decide.
|
|
81
|
+
fn score(&self) -> f64 {
|
|
82
|
+
self.score
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// Returns the dependency as a plain Hash.
|
|
86
|
+
///
|
|
87
|
+
/// # Returns
|
|
88
|
+
///
|
|
89
|
+
/// A Hash with the symbol keys `:sentence`, `:bunsetsu`, `:head` (nil
|
|
90
|
+
/// for the last bunsetsu of a sentence), `:role` and `:score`.
|
|
91
|
+
fn to_hash(ruby: &Ruby, rb_self: &Self) -> Result<RHash, Error> {
|
|
92
|
+
let hash = ruby.hash_new();
|
|
93
|
+
hash.aset(ruby.to_symbol("sentence"), rb_self.sentence)?;
|
|
94
|
+
hash.aset(ruby.to_symbol("bunsetsu"), rb_self.bunsetsu)?;
|
|
95
|
+
hash.aset(ruby.to_symbol("head"), rb_self.head)?;
|
|
96
|
+
hash.aset(ruby.to_symbol("role"), rb_self.role)?;
|
|
97
|
+
hash.aset(ruby.to_symbol("score"), rb_self.score)?;
|
|
98
|
+
Ok(hash)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// Returns the inspect representation of the dependency.
|
|
102
|
+
fn inspect(&self) -> String {
|
|
103
|
+
let head = match self.head {
|
|
104
|
+
Some(head) => head.to_string(),
|
|
105
|
+
None => "nil".to_string(),
|
|
106
|
+
};
|
|
107
|
+
format!(
|
|
108
|
+
"#<Lindera::TokenDependency sentence={}, bunsetsu={}, head={}, role='{}', score={}>",
|
|
109
|
+
self.sentence, self.bunsetsu, head, self.role, self.score
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
15
114
|
#[magnus::wrap(class = "Lindera::Token", free_immediately, size)]
|
|
16
115
|
pub struct RbToken {
|
|
17
116
|
/// Surface form of the token.
|
|
@@ -28,6 +127,9 @@ pub struct RbToken {
|
|
|
28
127
|
is_unknown: bool,
|
|
29
128
|
/// Morphological details of the token.
|
|
30
129
|
details: Vec<String>,
|
|
130
|
+
/// The bunsetsu of the token and its head, when the token filter
|
|
131
|
+
/// `japanese_dependency` ran.
|
|
132
|
+
dependency: Option<RbTokenDependency>,
|
|
31
133
|
}
|
|
32
134
|
|
|
33
135
|
impl RbToken {
|
|
@@ -62,6 +164,7 @@ impl RbToken {
|
|
|
62
164
|
word_id: view.word_id,
|
|
63
165
|
is_unknown: view.is_unknown,
|
|
64
166
|
details: view.details,
|
|
167
|
+
dependency: view.dependency.map(RbTokenDependency::from_view),
|
|
65
168
|
}
|
|
66
169
|
}
|
|
67
170
|
|
|
@@ -100,6 +203,12 @@ impl RbToken {
|
|
|
100
203
|
self.details.clone()
|
|
101
204
|
}
|
|
102
205
|
|
|
206
|
+
/// Returns the bunsetsu of the token and its head, or nil unless the
|
|
207
|
+
/// token filter `japanese_dependency` ran.
|
|
208
|
+
fn dependency(&self) -> Option<RbTokenDependency> {
|
|
209
|
+
self.dependency.clone()
|
|
210
|
+
}
|
|
211
|
+
|
|
103
212
|
/// Returns the detail at the specified index.
|
|
104
213
|
///
|
|
105
214
|
/// # Arguments
|
|
@@ -127,8 +236,9 @@ impl RbToken {
|
|
|
127
236
|
/// # Returns
|
|
128
237
|
///
|
|
129
238
|
/// A Hash with the keys `:surface`, `:byte_start`, `:byte_end`,
|
|
130
|
-
/// `:position`, `:word_id`, `:is_unknown`,
|
|
131
|
-
/// `
|
|
239
|
+
/// `:position`, `:word_id`, `:is_unknown`, `:details`, and
|
|
240
|
+
/// `:dependency` (nil, or the Hash of `TokenDependency#to_h`), or a
|
|
241
|
+
/// Magnus `Error` if the Hash cannot be built.
|
|
132
242
|
fn to_hash(ruby: &Ruby, rb_self: &Self) -> Result<RHash, Error> {
|
|
133
243
|
let this = rb_self;
|
|
134
244
|
let hash = ruby.hash_new();
|
|
@@ -143,6 +253,13 @@ impl RbToken {
|
|
|
143
253
|
details.push(detail.as_str())?;
|
|
144
254
|
}
|
|
145
255
|
hash.aset(ruby.to_symbol("details"), details)?;
|
|
256
|
+
match &this.dependency {
|
|
257
|
+
Some(dependency) => hash.aset(
|
|
258
|
+
ruby.to_symbol("dependency"),
|
|
259
|
+
RbTokenDependency::to_hash(ruby, dependency)?,
|
|
260
|
+
)?,
|
|
261
|
+
None => hash.aset(ruby.to_symbol("dependency"), ruby.qnil())?,
|
|
262
|
+
}
|
|
146
263
|
Ok(hash)
|
|
147
264
|
}
|
|
148
265
|
|
|
@@ -188,8 +305,19 @@ pub fn define(ruby: &Ruby, module: &magnus::RModule) -> Result<(), Error> {
|
|
|
188
305
|
token_class.define_method("to_hash", method!(RbToken::to_hash, 0))?;
|
|
189
306
|
token_class.define_method("to_h", method!(RbToken::to_hash, 0))?;
|
|
190
307
|
|
|
308
|
+
token_class.define_method("dependency", method!(RbToken::dependency, 0))?;
|
|
191
309
|
token_class.define_method("to_s", method!(RbToken::to_s, 0))?;
|
|
192
310
|
token_class.define_method("inspect", method!(RbToken::inspect, 0))?;
|
|
193
311
|
|
|
312
|
+
let dependency_class = module.define_class("TokenDependency", ruby.class_object())?;
|
|
313
|
+
dependency_class.define_method("sentence", method!(RbTokenDependency::sentence, 0))?;
|
|
314
|
+
dependency_class.define_method("bunsetsu", method!(RbTokenDependency::bunsetsu, 0))?;
|
|
315
|
+
dependency_class.define_method("head", method!(RbTokenDependency::head, 0))?;
|
|
316
|
+
dependency_class.define_method("role", method!(RbTokenDependency::role, 0))?;
|
|
317
|
+
dependency_class.define_method("score", method!(RbTokenDependency::score, 0))?;
|
|
318
|
+
dependency_class.define_method("to_hash", method!(RbTokenDependency::to_hash, 0))?;
|
|
319
|
+
dependency_class.define_method("to_h", method!(RbTokenDependency::to_hash, 0))?;
|
|
320
|
+
dependency_class.define_method("inspect", method!(RbTokenDependency::inspect, 0))?;
|
|
321
|
+
|
|
194
322
|
Ok(())
|
|
195
323
|
}
|
data/src/trainer.rs
CHANGED
|
@@ -209,7 +209,7 @@ fn train(ruby: &Ruby, args: &[Value]) -> Result<(), Error> {
|
|
|
209
209
|
|
|
210
210
|
/// Export dictionary files from trained model.
|
|
211
211
|
///
|
|
212
|
-
/// Writes the files `lindera export` writes, with the same method
|
|
212
|
+
/// Writes the files `lindera dictionary export` writes, with the same method
|
|
213
213
|
/// (`SerializableModel::export`): `lex.csv`, `matrix.def`, `unk.def`,
|
|
214
214
|
/// `char.def`, `feature.def`, `rewrite.def`, `left-id.def` and
|
|
215
215
|
/// `right-id.def`, and `metadata.json` when `metadata` is given.
|