2020-09-28 07:28:21 -04:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This downloads and compiles Nori dictionaries.
|
|
|
|
|
|
|
|
def recompileDictionary(project, dictionaryName, Closure closure) {
|
|
|
|
project.javaexec {
|
|
|
|
main = "org.apache.lucene.analysis.ko.util.DictionaryBuilder"
|
|
|
|
classpath = project.sourceSets.main.runtimeClasspath
|
|
|
|
|
|
|
|
jvmArgs '-Xmx1G'
|
|
|
|
|
|
|
|
with closure
|
|
|
|
}
|
|
|
|
project.logger.lifecycle("Automaton regenerated from dictionary: ${dictionaryName}")
|
|
|
|
}
|
|
|
|
|
|
|
|
configure(project(":lucene:analysis:nori")) {
|
|
|
|
apply plugin: "de.undercouch.download"
|
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
plugins.withType(JavaPlugin) {
|
|
|
|
ext {
|
|
|
|
targetDir = file("src/resources")
|
|
|
|
}
|
2020-09-28 07:28:21 -04:00
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
task deleteDictionaryData() {
|
|
|
|
// There should really be just one but since we don't know which
|
|
|
|
// one it'll be, let's process all of them.
|
|
|
|
doFirst {
|
|
|
|
sourceSets.main.resources.srcDirs.each { location ->
|
|
|
|
delete fileTree(dir: location, include: "org/apache/lucene/analysis/ko/dict/*.dat")
|
|
|
|
}
|
2020-09-28 07:28:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
task compileMecabKo(type: Download) {
|
|
|
|
description "Recompile dictionaries from Mecab-Ko data."
|
|
|
|
group "generation"
|
2020-09-28 07:28:21 -04:00
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
dependsOn deleteDictionaryData
|
|
|
|
dependsOn sourceSets.main.runtimeClasspath
|
2020-09-28 07:28:21 -04:00
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
def dictionaryName = "mecab-ko-dic-2.0.3-20170922"
|
|
|
|
def dictionarySource = "https://bitbucket.org/eunjeon/mecab-ko-dic/downloads/${dictionaryName}.tar.gz"
|
|
|
|
def dictionaryFile = file("${buildDir}/generate/${dictionaryName}.tar.gz")
|
|
|
|
def unpackedDir = file("${buildDir}/generate/${dictionaryName}")
|
2020-09-28 07:28:21 -04:00
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
src dictionarySource
|
|
|
|
dest dictionaryFile
|
|
|
|
onlyIfModified true
|
2020-09-28 07:28:21 -04:00
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
doLast {
|
|
|
|
// Unpack the downloaded archive.
|
|
|
|
delete unpackedDir
|
|
|
|
ant.untar(src: dictionaryFile, dest: unpackedDir, compression: "gzip") {
|
|
|
|
ant.cutdirsmapper(dirs: "1")
|
|
|
|
}
|
2020-09-28 07:28:21 -04:00
|
|
|
|
2020-09-29 03:41:36 -04:00
|
|
|
// Compile the dictionary
|
|
|
|
recompileDictionary(project, dictionaryName, {
|
|
|
|
args += [
|
|
|
|
unpackedDir,
|
|
|
|
targetDir,
|
|
|
|
"utf-8",
|
|
|
|
false
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
2020-09-28 07:28:21 -04:00
|
|
|
}
|
2021-03-23 04:25:53 -04:00
|
|
|
|
|
|
|
regenerate.dependsOn compileMecabKo
|
2020-09-28 07:28:21 -04:00
|
|
|
}
|
|
|
|
}
|