Skip to content

Commit ef73aeb

Browse files
authored
Merge pull request #33 from codingpot/feat/verup-0.10.3
feat: add splitSentence
2 parents 92297db + 94dd48f commit ef73aeb

4 files changed

Lines changed: 56 additions & 17 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,11 @@ ARG NODE_VERSION="none"
99
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
1010

1111
# [Optional] Uncomment this section to install additional OS packages.
12-
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
13-
&& apt-get -y install --no-install-recommends cmake \
14-
&& git clone https://github.com/bab2min/Kiwi.git \
15-
&& cd Kiwi \
16-
&& git submodule sync \
17-
&& git submodule update --init --recursive \
18-
&& mkdir build \
19-
&& cd build \
20-
&& cmake -DCMAKE_BUILD_TYPE=Release ../ \
21-
&& make && make install \
22-
&& ldconfig \
23-
&& cd ../.. && rm -rf Kiwi \
24-
&& apt-get --purge -y remove cmake \
25-
&& apt autoremove -y \
26-
&& rm -rf /var/lib/apt/lists/*
12+
#RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
13+
# && apt-get -y install --no-install-recommends cmake \
14+
# && apt-get --purge -y remove cmake \
15+
# && apt autoremove -y \
16+
# && rm -rf /var/lib/apt/lists/*
2717

2818

2919
RUN sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- --yes

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KIWI_VERSION := "v0.10.2"
1+
KIWI_VERSION := "v0.10.3"
22

33
.PHONY: test
44
test: ModelGenerator/default.dict

kiwi.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,34 @@ func (k *Kiwi) Analyze(text string, topN int, options AnalyzeOption) ([]TokenRes
122122
return res, nil
123123
}
124124

125+
// SplitResult returns the Sentences.
126+
type SplitResult struct {
127+
Text string
128+
Begin int
129+
End int
130+
}
131+
132+
// SplitSentence returns the line of sentences.
133+
func (k *Kiwi) SplitSentence(text string, options AnalyzeOption) ([]SplitResult, error) {
134+
kiwiSsH := C.kiwi_split_into_sents(k.handler, C.CString(text), C.int(options), nil)
135+
defer C.kiwi_ss_close(kiwiSsH)
136+
137+
resSize := int(C.kiwi_ss_size(kiwiSsH))
138+
res := make([]SplitResult, resSize)
139+
140+
for i := 0; i < resSize; i++ {
141+
begin := int(C.kiwi_ss_begin_position(kiwiSsH, C.int(i)))
142+
end := int(C.kiwi_ss_end_position(kiwiSsH, C.int(i)))
143+
res[i] = SplitResult{
144+
Text: text[begin:end],
145+
Begin: begin,
146+
End: end,
147+
}
148+
}
149+
150+
return res, nil
151+
}
152+
125153
// Close frees the resource allocated for Kiwi and returns the exit status.
126154
// This must be called after New.
127155
// Returns 0 if successful.

kiwi_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestKiwiVersion(t *testing.T) {
12-
assert.Equal(t, KiwiVersion(), "0.10.2")
12+
assert.Equal(t, KiwiVersion(), "0.10.3")
1313
}
1414

1515
func TestAnalyze(t *testing.T) {
@@ -63,6 +63,27 @@ func TestAnalyze(t *testing.T) {
6363
assert.Equal(t, 0, kiwi.Close())
6464
}
6565

66+
func TestSplitSentence(t *testing.T) {
67+
kiwi := New("./ModelGenerator", 1, KIWI_BUILD_DEFAULT)
68+
res, _ := kiwi.SplitSentence("여러 문장으로 구성된 텍스트네 이걸 분리해줘", KIWI_MATCH_ALL)
69+
70+
expected := []SplitResult{
71+
{
72+
Text: "여러 문장으로 구성된 텍스트네",
73+
Begin: 0,
74+
End: 42,
75+
},
76+
{
77+
Text: "이걸 분리해줘",
78+
Begin: 43,
79+
End: 62,
80+
},
81+
}
82+
83+
assert.Equal(t, expected, res)
84+
assert.Equal(t, 0, kiwi.Close())
85+
}
86+
6687
func TestAddWordFail(t *testing.T) {
6788
kb := NewBuilder("./ModelGenerator", 1, KIWI_BUILD_INTEGRATE_ALLOMORPH)
6889
add := kb.AddWord("아버지가", "SKO", 0)

0 commit comments

Comments
 (0)