Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
news
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sartika Aritonang
news
Commits
15a6a0ca
Commit
15a6a0ca
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
6c019d71
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
StemmerFactory.py
stbi/Lib/site-packages/Sastrawi/Stemmer/StemmerFactory.py
+44
-0
No files found.
stbi/Lib/site-packages/Sastrawi/Stemmer/StemmerFactory.py
0 → 100644
View file @
15a6a0ca
import
os
from
Sastrawi.Dictionary.ArrayDictionary
import
ArrayDictionary
from
Sastrawi.Stemmer.Stemmer
import
Stemmer
from
Sastrawi.Stemmer.CachedStemmer
import
CachedStemmer
from
Sastrawi.Stemmer.Cache.ArrayCache
import
ArrayCache
class
StemmerFactory
(
object
):
""" Stemmer factory helps creating pre-configured stemmer """
APC_KEY
=
'sastrawi_cache_dictionary'
def
create_stemmer
(
self
,
isDev
=
False
):
""" Returns Stemmer instance """
words
=
self
.
get_words
(
isDev
)
dictionary
=
ArrayDictionary
(
words
)
stemmer
=
Stemmer
(
dictionary
)
resultCache
=
ArrayCache
()
cachedStemmer
=
CachedStemmer
(
resultCache
,
stemmer
)
return
cachedStemmer
def
get_words
(
self
,
isDev
=
False
):
#if isDev or callable(getattr(self, 'apc_fetch')):
# words = self.getWordsFromFile()
#else:
# words = apc_fetch(self.APC_KEY)
# if not words:
# words = self.getWordsFromFile()
# apc_store(self.APC_KEY, words)
return
self
.
get_words_from_file
()
def
get_words_from_file
(
self
):
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
dictionaryFile
=
current_dir
+
'/data/kata-dasar.txt'
if
not
os
.
path
.
isfile
(
dictionaryFile
):
raise
RuntimeError
(
'Dictionary file is missing. It seems that your installation is corrupted.'
)
dictionaryContent
=
''
with
open
(
dictionaryFile
,
'r'
)
as
f
:
dictionaryContent
=
f
.
read
()
return
dictionaryContent
.
split
(
'
\n
'
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment