Browse Source

Added mecab and mecab test

master
Macoy Madson 6 months ago
parent
commit
0195f754fb
8 changed files with 107 additions and 4 deletions
  1. +3
    -0
      .gitmodules
  2. +15
    -0
      BuildDependencies_Debug.sh
  3. +1
    -0
      Dependencies/mecab
  4. +3
    -0
      Jamfile
  5. +6
    -2
      Jamrules
  6. +1
    -1
      ReadMe.org
  7. +1
    -1
      src/Main.cpp
  8. +77
    -0
      src/TextTest.cpp

+ 3
- 0
.gitmodules View File

@@ -4,3 +4,6 @@
[submodule "Dependencies/rapidjson"]
path = Dependencies/rapidjson
url = https://github.com/Tencent/rapidjson
[submodule "Dependencies/mecab"]
path = Dependencies/mecab
url = https://github.com/taku910/mecab

+ 15
- 0
BuildDependencies_Debug.sh View File

@@ -8,3 +8,18 @@ curl_dir=$(echo $PWD/local_install)
make -j4
make install
cd ../../

echo "Building mecab..."
cd Dependencies/mecab # Root of repo
mkdir build
cd build
output=$(pwd)
../mecab/configure --prefix=$output/local CC=clang CXX=clang++ CXXFLAGS="-g" --with-charset=utf8
make -j4
make install # Must do this before making the dictionary

# Dictionary must be built in directory
cd ../mecab-ipadic
./configure --prefix=$output/local CC=clang CXX=clang++ CXXFLAGS="-g" --with-charset=utf8 --with-mecab-config=$output/local/bin/mecab-config
make
make install

+ 1
- 0
Dependencies/mecab

@@ -0,0 +1 @@
Subproject commit 3a07c4eefaffb4e7a0690a7f4e5e0263d3ddb8a3

+ 3
- 0
Jamfile View File

@@ -3,6 +3,9 @@ SubDir . ;
Main japanese_for_me : src/Main.cpp
;

Main test_mecab : src/TextTest.cpp
;

LinkLibraries japanese_for_me : libJFMNotify ;

Library libJFMNotify : $(NOTIFY_IMPLEMENTATION_FILES) ;


+ 6
- 2
Jamrules View File

@@ -29,6 +29,7 @@ HDRS = src
# Dependencies/tracy
Dependencies/curl/include
Dependencies/rapidjson/include
Dependencies/mecab/build/local/include
;

# TODO: Make base hold all this weirdness?
@@ -59,7 +60,7 @@ if $(LIBNOTIFY_AVAILABLE)
}
else
{
NOTIFY_LINKLIBS = ;
NOTIFY_LINKLIBS = ;
NOTIFY_HEADERS = ;
NOTIFY_IMPLEMENTATION_FILES = src/Notifications_Stub.cpp ;
}
@@ -74,6 +75,9 @@ $(NOTIFY_LINKLIBS)
-LDependencies/curl/local_install/lib
-lcurl

-LDependencies/mecab/build/local/lib
-lmecab

# SFML
# -LDependencies/base2.0/dependencies/SFML/lib
# $(SFML_LINKLIBS)
@@ -91,7 +95,7 @@ $(NOTIFY_LINKLIBS)

# TODO: Copy libs to better directory, or static link?
LINKFLAGS = -g
-Wl,-rpath,.:Dependencies/curl/local_install/lib ;
-Wl,-rpath,.:Dependencies/curl/local_install/lib:Dependencies/mecab/build/local/lib ;

##
## Jam stuff


+ 1
- 1
ReadMe.org View File

@@ -27,7 +27,7 @@ Anki is used to manage spaced repitition.
- [[https://foosoft.net/projects/anki-connect/index.html#installation][Install AnkiConnect]]
- Run Anki
** Building
Build CURL:
Build CURL and Mecab:
#+BEGIN_SRC sh
./BuildDependencies_Debug.sh
#+END_SRC


+ 1
- 1
src/Main.cpp View File

@@ -280,7 +280,7 @@ int main()
{
std::cout << "Japanese For Me\nA vocabulary learning app by Macoy Madson.\n\n";

std::chrono::steady_clock::time_point programStartTime = std::chrono::steady_clock::now();
// std::chrono::steady_clock::time_point programStartTime = std::chrono::steady_clock::now();

curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();


+ 77
- 0
src/TextTest.cpp View File

@@ -0,0 +1,77 @@
#include <mecab.h>
#include <iostream>

#define CHECK(eval) \
if (!eval) \
{ \
const char* e = tagger ? tagger->what() : MeCab::getTaggerError(); \
std::cerr << "Exception:" << e << std::endl; \
delete tagger; \
return -1; \
}

// Sample of MeCab::Tagger class.
int main(int argc, char** argv)
{
char input[1024] =
"\u592a\u90ce\u306f\u6b21\u90ce\u304c\u6301\u3063\u3066\u3044\u308b\u672c\u3092\u82b1\u5b50"
"\u306b\u6e21\u3057\u305f\u3002";

MeCab::Tagger* tagger = MeCab::createTagger("");
CHECK(tagger);

// Gets tagged result in string format.
const char* result = tagger->parse(input);
CHECK(result);
std::cout << "INPUT: " << input << std::endl;
std::cout << "RESULT: " << result << std::endl;

// Gets N best results in string format.
result = tagger->parseNBest(3, input);
CHECK(result);
std::cout << "NBEST: " << std::endl << result;

// Gets N best results in sequence.
CHECK(tagger->parseNBestInit(input));
for (int i = 0; i < 3; ++i)
{
std::cout << i << ":" << std::endl << tagger->next();
}

// Gets Node object.
const MeCab::Node* node = tagger->parseToNode(input);
CHECK(node);
for (; node; node = node->next)
{
std::cout << node->id << ' ';
if (node->stat == MECAB_BOS_NODE)
std::cout << "BOS";
else if (node->stat == MECAB_EOS_NODE)
std::cout << "EOS";
else
std::cout.write(node->surface, node->length);

std::cout << ' ' << node->feature << ' ' << (int)(node->surface - input) << ' '
<< (int)(node->surface - input + node->length) << ' ' << node->rcAttr << ' '
<< node->lcAttr << ' ' << node->posid << ' ' << (int)node->char_type << ' '
<< (int)node->stat << ' ' << (int)node->isbest << ' ' << node->alpha << ' '
<< node->beta << ' ' << node->prob << ' ' << node->cost << std::endl;
}

// Dictionary info.
const MeCab::DictionaryInfo* d = tagger->dictionary_info();
for (; d; d = d->next)
{
std::cout << "filename: " << d->filename << std::endl;
std::cout << "charset: " << d->charset << std::endl;
std::cout << "size: " << d->size << std::endl;
std::cout << "type: " << d->type << std::endl;
std::cout << "lsize: " << d->lsize << std::endl;
std::cout << "rsize: " << d->rsize << std::endl;
std::cout << "version: " << d->version << std::endl;
}

delete tagger;

return 0;
}

Loading…
Cancel
Save