-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9d22dbb
Showing
61 changed files
with
169,250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Taku Kudo <taku@chasen.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Copyright (c) 2001-2008, Taku Kudo | ||
Copyright (c) 2004-2008, Nippon Telegraph and Telephone Corporation | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are | ||
permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above | ||
copyright notice, this list of conditions and the | ||
following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the | ||
following disclaimer in the documentation and/or other | ||
materials provided with the distribution. | ||
|
||
* Neither the name of the Nippon Telegraph and Telegraph Corporation | ||
nor the names of its contributors may be used to endorse or | ||
promote products derived from this software without specific | ||
prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MeCab is copyrighted free software by Taku Kudo <taku@chasen.org> and | ||
Nippon Telegraph and Telephone Corporation, and is released under | ||
any of the GPL (see the file GPL), the LGPL (see the file LGPL), or the | ||
BSD License (see the file BSD). |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
See doc/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// swift-tools-version:5.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "mecab", | ||
products: [ | ||
.library( | ||
name: "mecab", | ||
type: .dynamic, | ||
targets: ["mecab"] | ||
), | ||
], | ||
targets: [ | ||
.target( | ||
name: "mecab", | ||
dependencies: [], | ||
cxxSettings: [ | ||
.define("HAVE_CONFIG_H"), | ||
.define("DIC_VERSION", to: "102"), | ||
.define("MECAB_DEFAULT_RC", to: "\"./\"") | ||
], | ||
linkerSettings: [.linkedLibrary("iconv")] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MeCab for Swift Package Manager | ||
===== | ||
### MeCab Dynamic Framework for Swift Package Manager | ||
|
||
originally forked from | ||
[~~FLCLjp/iPhone-libmecab~~](https://github.com/FLCLjp/iPhone-libmecab) (mirror here [rnorth/iPhone-libmecab](https://github.com/rnorth/iPhone-libmecab)) | ||
|
||
MeCab source code updated to current version from [taku910/mecab](https://github.com/taku910/mecab) | ||
(commit [3a07c4e](https://github.com/taku910/mecab/commit/3a07c4eefaffb4e7a0690a7f4e5e0263d3ddb8a3) on Mar 18, 2018) | ||
|
||
### Reference | ||
http://d.hatena.ne.jp/seiyan1978/comment?date=20111116§ion=1321461642 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
// MeCab -- Yet Another Part-of-Speech and Morphological Analyzer | ||
// | ||
// | ||
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org> | ||
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation | ||
#include <fstream> | ||
#include <map> | ||
#include <vector> | ||
#include <set> | ||
#include <string> | ||
#include <sstream> | ||
#include "char_property.h" | ||
#include "common.h" | ||
#include "mmap.h" | ||
#include "param.h" | ||
#include "utils.h" | ||
|
||
namespace MeCab { | ||
|
||
namespace { | ||
struct Range { | ||
int low; | ||
int high; | ||
std::vector<std::string> c; | ||
}; | ||
|
||
int atohex(const char *s) { | ||
int n = 0; | ||
|
||
CHECK_DIE(std::strlen(s) >= 3 | ||
&& s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) | ||
<< "no hex value: " << s; | ||
|
||
const char *p = s; | ||
s += 2; | ||
while (*s) { | ||
int r = 0; | ||
if (*s >= '0' && *s <= '9') | ||
r = *s - '0'; | ||
else if (*s >= 'A' && *s <= 'F') | ||
r = *s - 'A' + 10; | ||
else if (*s >= 'a' && *s <= 'f') | ||
r = *s - 'a' + 10; | ||
else | ||
CHECK_DIE(false) << "no hex value: " << p; | ||
|
||
n = 16 * n + r; | ||
s++; | ||
} | ||
|
||
return n; | ||
} | ||
|
||
CharInfo encode(const std::vector<std::string> &c, | ||
std::map<std::string, CharInfo> *category) { | ||
CHECK_DIE(c.size()) << "category size is empty"; | ||
|
||
std::map<std::string, CharInfo>::const_iterator it = category->find(c[0]); | ||
CHECK_DIE(it != category->end()) | ||
<< "category [" << c[0] << "] is undefined"; | ||
|
||
CharInfo base = it->second; | ||
for (size_t i = 0; i < c.size(); ++i) { | ||
std::map<std::string, CharInfo>::const_iterator it = | ||
category->find(c[i]); | ||
CHECK_DIE(it != category->end()) | ||
<< "category [" << c[i] << "] is undefined"; | ||
base.type += (1 << it->second.default_type); | ||
} | ||
|
||
return base; | ||
} | ||
} | ||
|
||
bool CharProperty::open(const Param ¶m) { | ||
const std::string prefix = param.get<std::string>("dicdir"); | ||
const std::string filename = create_filename(prefix, CHAR_PROPERTY_FILE); | ||
return open(filename.c_str()); | ||
} | ||
|
||
bool CharProperty::open(const char *filename) { | ||
std::ostringstream error; | ||
CHECK_FALSE(cmmap_->open(filename, "r")); | ||
|
||
const char *ptr = cmmap_->begin(); | ||
unsigned int csize; | ||
read_static<unsigned int>(&ptr, csize); | ||
|
||
size_t fsize = sizeof(unsigned int) + | ||
(32 * csize) + sizeof(unsigned int) * 0xffff; | ||
|
||
CHECK_FALSE(fsize == cmmap_->size()) | ||
<< "invalid file size: " << filename; | ||
|
||
clist_.clear(); | ||
for (unsigned int i = 0; i < csize; ++i) { | ||
const char *s = read_ptr(&ptr, 32); | ||
clist_.push_back(s); | ||
} | ||
|
||
map_ = reinterpret_cast<const CharInfo *>(ptr); | ||
|
||
return true; | ||
} | ||
|
||
void CharProperty::close() { | ||
cmmap_->close(); | ||
} | ||
|
||
size_t CharProperty::size() const { return clist_.size(); } | ||
|
||
const char *CharProperty::name(size_t i) const { | ||
return const_cast<const char*>(clist_[i]); | ||
} | ||
|
||
// this function must be rewritten. | ||
void CharProperty::set_charset(const char *ct) { | ||
charset_ = decode_charset(ct); | ||
} | ||
|
||
int CharProperty::id(const char *key) const { | ||
for (int i = 0; i < static_cast<long>(clist_.size()); ++i) { | ||
if (std::strcmp(key, clist_[i]) == 0) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
bool CharProperty::compile(const char *cfile, | ||
const char *ufile, | ||
const char *ofile) { | ||
scoped_fixed_array<char, BUF_SIZE> line; | ||
scoped_fixed_array<char *, 512> col; | ||
size_t id = 0; | ||
std::vector<Range> range; | ||
std::map<std::string, CharInfo> category; | ||
std::vector<std::string> category_ary; | ||
std::ifstream ifs(WPATH(cfile)); | ||
std::istringstream iss(CHAR_PROPERTY_DEF_DEFAULT); | ||
std::istream *is = &ifs; | ||
|
||
if (!ifs) { | ||
std::cerr << cfile | ||
<< " is not found. minimum setting is used" << std::endl; | ||
is = &iss; | ||
} | ||
|
||
while (is->getline(line.get(), line.size())) { | ||
if (std::strlen(line.get()) == 0 || line[0] == '#') { | ||
continue; | ||
} | ||
const size_t size = tokenize2(line.get(), "\t ", col.get(), col.size()); | ||
CHECK_DIE(size >= 2) << "format error: " << line.get(); | ||
|
||
// 0xFFFF..0xFFFF hoge hoge hgoe # | ||
if (std::strncmp(col[0], "0x", 2) == 0) { | ||
std::string low = col[0]; | ||
std::string high; | ||
size_t pos = low.find(".."); | ||
|
||
if (pos != std::string::npos) { | ||
high = low.substr(pos + 2, low.size() - pos - 2); | ||
low = low.substr(0, pos); | ||
} else { | ||
high = low; | ||
} | ||
|
||
Range r; | ||
r.low = atohex(low.c_str()); | ||
r.high = atohex(high.c_str()); | ||
|
||
CHECK_DIE(r.low >= 0 && r.low < 0xffff && | ||
r.high >= 0 && r.high < 0xffff && | ||
r.low <= r.high) | ||
<< "range error: low=" << r.low << " high=" << r.high; | ||
|
||
for (size_t i = 1; i < size; ++i) { | ||
if (col[i][0] == '#') { | ||
break; // skip comments | ||
} | ||
CHECK_DIE(category.find(std::string(col[i])) != category.end()) | ||
<< "category [" << col[i] << "] is undefined"; | ||
r.c.push_back(col[i]); | ||
} | ||
range.push_back(r); | ||
} else { | ||
CHECK_DIE(size >= 4) << "format error: " << line.get(); | ||
|
||
std::string key = col[0]; | ||
CHECK_DIE(category.find(key) == category.end()) | ||
<< "category " << key << " is already defined"; | ||
|
||
CharInfo c; | ||
std::memset(&c, 0, sizeof(c)); | ||
c.invoke = std::atoi(col[1]); | ||
c.group = std::atoi(col[2]); | ||
c.length = std::atoi(col[3]); | ||
c.default_type = id++; | ||
|
||
category.insert(std::pair<std::string, CharInfo>(key, c)); | ||
category_ary.push_back(key); | ||
} | ||
} | ||
|
||
CHECK_DIE(category.size() < 18) << "too many categories(>= 18)"; | ||
|
||
CHECK_DIE(category.find("DEFAULT") != category.end()) | ||
<< "category [DEFAULT] is undefined"; | ||
|
||
CHECK_DIE(category.find("SPACE") != category.end()) | ||
<< "category [SPACE] is undefined"; | ||
|
||
std::istringstream iss2(UNK_DEF_DEFAULT); | ||
std::ifstream ifs2(WPATH(ufile)); | ||
std::istream *is2 = &ifs2; | ||
|
||
if (!ifs2) { | ||
std::cerr << ufile | ||
<< " is not found. minimum setting is used." << std::endl; | ||
is2 = &iss2; | ||
} | ||
|
||
std::set<std::string> unk; | ||
while (is2->getline(line.get(), line.size())) { | ||
const size_t n = tokenizeCSV(line.get(), col.get(), 2); | ||
CHECK_DIE(n >= 1) << "format error: " << line.get(); | ||
const std::string key = col[0]; | ||
CHECK_DIE(category.find(key) != category.end()) | ||
<< "category [" << key << "] is undefined in " << cfile; | ||
unk.insert(key); | ||
} | ||
|
||
for (std::map<std::string, CharInfo>::const_iterator it = category.begin(); | ||
it != category.end(); | ||
++it) { | ||
CHECK_DIE(unk.find(it->first) != unk.end()) | ||
<< "category [" << it->first << "] is undefined in " << ufile; | ||
} | ||
|
||
std::vector<CharInfo> table(0xffff); | ||
{ | ||
std::vector<std::string> tmp; | ||
tmp.push_back("DEFAULT"); | ||
const CharInfo c = encode(tmp, &category); | ||
std::fill(table.begin(), table.end(), c); | ||
} | ||
|
||
for (std::vector<Range>::const_iterator it = range.begin(); | ||
it != range.end(); | ||
++it) { | ||
const CharInfo c = encode(it->c, &category); | ||
for (int i = it->low; i <= it->high; ++i) { | ||
table[i] = c; | ||
} | ||
} | ||
|
||
// output binary table | ||
{ | ||
std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out); | ||
CHECK_DIE(ofs) << "permission denied: " << ofile; | ||
|
||
unsigned int size = static_cast<unsigned int>(category.size()); | ||
ofs.write(reinterpret_cast<const char*>(&size), sizeof(size)); | ||
for (std::vector<std::string>::const_iterator it = category_ary.begin(); | ||
it != category_ary.end(); | ||
++it) { | ||
char buf[32]; | ||
std::fill(buf, buf + sizeof(buf), '\0'); | ||
std::strncpy(buf, it->c_str(), sizeof(buf) - 1); | ||
ofs.write(reinterpret_cast<const char*>(buf), sizeof(buf)); | ||
} | ||
ofs.write(reinterpret_cast<const char*>(&table[0]), | ||
sizeof(CharInfo) * table.size()); | ||
ofs.close(); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.