gibasa

A plain ‘Rcpp’ wrapper of ‘MeCab'

https://github.com/paithiov909/gibasa

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.7%) to scientific vocabulary

Keywords

mecab pos-tagging r r-package rcpp
Last synced: 6 months ago · JSON representation

Repository

A plain ‘Rcpp’ wrapper of ‘MeCab'

Basic Info
Statistics
  • Stars: 16
  • Watchers: 1
  • Forks: 1
  • Open Issues: 1
  • Releases: 19
Topics
mecab pos-tagging r r-package rcpp
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
pkgload::load_all(export_all = FALSE)
```

# gibasa


[![gibasa status badge](https://paithiov909.r-universe.dev/badges/gibasa)](https://paithiov909.r-universe.dev/gibasa)
![GitHub](https://img.shields.io/github/license/paithiov909/gibasa)
[![R-CMD-check](https://github.com/paithiov909/gibasa/workflows/R-CMD-check/badge.svg)](https://github.com/paithiov909/gibasa/actions)
[![codecov](https://codecov.io/gh/paithiov909/gibasa/branch/main/graph/badge.svg)](https://app.codecov.io/gh/paithiov909/gibasa)
[![CRAN logs badge](https://cranlogs.r-pkg.org/badges/gibasa)](https://cran.r-project.org/package=gibasa)


## Overview

gibasa is a plain 'Rcpp' wrapper for 'MeCab', a morphological analyzer for CJK text.

Part-of-speech tagging with morphological analyzers is useful for processing CJK text data. This is because most words in CJK text are not separated by whitespaces and `tokenizers::tokenize_words` may split them into wrong tokens.

The main goal of gibasa package is to provide an alternative to `tidytext::unnest_tokens` for CJK text data. For this goal, gibasa provides three main functions: `gibasa::tokenize`, `gibasa::prettify`, and `gibasa::pack`.

![flowchart of a text analysis that combines gibasa and other packages](man/figures/tidytext_fig5_1_mod.drawio.png)

- `gibasa::tokenize` takes a TIF-compliant data.frame of corpus, returning tokens as format that known as 'tidy text data', so that users can replace `tidytext::unnest_tokens` with it for tokenizing CJK text.
- `gibasa::prettify` turns tagged features into columns.
- `gibasa::pack` takes a 'tidy text data', typically returning space-separated corpus.

## Installation

You can install binary package via [CRAN](https://cran.r-project.org/package=gibasa) or [r-universe](https://paithiov909.r-universe.dev/gibasa).

```r
## Install gibasa from r-universe repository
install.packages("gibasa", repos = c("https://paithiov909.r-universe.dev", "https://cloud.r-project.org"))

## Or build from source package
Sys.setenv(MECAB_DEFAULT_RC = "/fullpath/to/your/mecabrc") # if necessary
remotes::install_github("paithiov909/gibasa")
```

To use gibasa package requires the [MeCab](https://taku910.github.io/mecab/) library and its dictionary installed and available.

In case using Linux or macOS, you can install them with their package managers, or build and install from the source by yourself.

In case using Windows, use installer [built for 64bit](https://github.com/ikegami-yukino/mecab/releases/tag/v0.996.2). Note that gibasa requires a UTF-8 dictionary, not a Shift-JIS one.

As of v0.9.4, gibasa looks at the file specified by the environment variable `MECABRC` or the file located at `~/.mecabrc`. If the MeCab dictionary is in a different location than the default, create a mecabrc file and specify where the dictionary is located.

For example, to install and use the [ipadic](https://pypi.org/project/ipadic/) from PyPI, run:

```sh
$ python3 -m pip install ipadic
$ python3 -c "import ipadic; print('dicdir=' + ipadic.DICDIR);" > ~/.mecabrc
```

## Usage

### Tokenize sentences

```{r}
res <- gibasa::tokenize(
  data.frame(
    doc_id = seq_along(gibasa::ginga[5:8]),
    text = gibasa::ginga[5:8]
  ),
  text,
  doc_id
)
res
```

### Prettify output

```{r}
gibasa::prettify(res)
gibasa::prettify(res, col_select = 1:3)
gibasa::prettify(res, col_select = c(1, 3, 5))
gibasa::prettify(res, col_select = c("POS1", "Original"))
```

### Pack output

```{r}
res <- gibasa::prettify(res)
gibasa::pack(res)

dplyr::mutate(
  res,
  token = dplyr::if_else(is.na(Original), token, Original),
  token = paste(token, POS1, sep = "/")
) |>
  gibasa::pack() |>
  head(1L)
```

### Change dictionary

IPA, UniDic, [CC-CEDICT-MeCab](https://github.com/ueda-keisuke/CC-CEDICT-MeCab), and [mecab-ko-dic](https://bitbucket.org/eunjeon/mecab-ko-dic/src/master/) schemes are supported.

```{r}
## UniDic 2.1.2
gibasa::tokenize("あのイーハトーヴォのすきとおった風", sys_dic = file.path("mecab/unidic-lite")) |>
  gibasa::prettify(into = gibasa::get_dict_features("unidic26"))


## CC-CEDICT
gibasa::tokenize("它可以进行日语和汉语的语态分析", sys_dic = file.path("mecab/cc-cedict")) |>
  gibasa::prettify(into = gibasa::get_dict_features("cc-cedict"))


## mecab-ko-dic
gibasa::tokenize("하네다공항한정토트백", sys_dic = file.path("mecab/mecab-ko-dic")) |>
  gibasa::prettify(into = gibasa::get_dict_features("ko-dic"))
```

## Build dictionaries

### Build a system dictionary

```{r}
## build a new ipadic in temporary directory
build_sys_dic(
  dic_dir = file.path("mecab/ipadic-eucjp"), # replace here with path to your source dictionary
  out_dir = tempdir(),
  encoding = "euc-jp" # encoding of source csv files
)

## copy the 'dicrc' file
file.copy(file.path("mecab/ipadic-eucjp/dicrc"), tempdir())

dictionary_info(sys_dic = tempdir())
```

### Build a user dictionary

```{r}
## write a csv file and compile it into a user dictionary
writeLines(
  c(
    "月ノ,1290,1290,4579,名詞,固有名詞,人名,姓,*,*,月ノ,ツキノ,ツキノ",
    "美兎,1291,1291,8561,名詞,固有名詞,人名,名,*,*,美兎,ミト,ミト"
  ),
  con = (csv_file <- tempfile(fileext = ".csv"))
)
build_user_dic(
  dic_dir = file.path("mecab/ipadic-eucjp"),
  file = (user_dic <- tempfile(fileext = ".dic")),
  csv_file = csv_file,
  encoding = "utf8"
)

tokenize("月ノ美兎は箱の中", sys_dic = tempdir(), user_dic = user_dic)
```

## License

GPL (>=3).

Owner

  • Name: Kato Akiru
  • Login: paithiov909
  • Kind: user
  • Location: Akita, Japan

@lyrikuso|加藤秋瑠はHNです

GitHub Events

Total
  • Release event: 1
  • Watch event: 2
  • Delete event: 2
  • Push event: 10
  • Pull request review event: 2
  • Pull request event: 4
  • Create event: 4
Last Year
  • Release event: 1
  • Watch event: 2
  • Delete event: 2
  • Push event: 10
  • Pull request review event: 2
  • Pull request event: 4
  • Create event: 4

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 266
  • Total Committers: 3
  • Avg Commits per committer: 88.667
  • Development Distribution Score (DDS): 0.023
Past Year
  • Commits: 17
  • Committers: 2
  • Avg Commits per committer: 8.5
  • Development Distribution Score (DDS): 0.059
Top Committers
Name Email Commits
paithiov909 a****4@g****m 260
renovate[bot] 2****] 4
imgbot[bot] 3****] 2

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 17
  • Total pull requests: 22
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 1 day
  • Total issue authors: 3
  • Total pull request authors: 3
  • Average comments per issue: 0.41
  • Average comments per pull request: 0.05
  • Merged pull requests: 20
  • Bot issues: 1
  • Bot pull requests: 8
Past Year
  • Issues: 0
  • Pull requests: 4
  • Average time to close issues: N/A
  • Average time to close pull requests: 6 days
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 4
Top Authors
Issue Authors
  • paithiov909 (15)
  • barracuda156 (1)
  • renovate[bot] (1)
Pull Request Authors
  • paithiov909 (14)
  • renovate[bot] (6)
  • imgbot[bot] (2)
Top Labels
Issue Labels
bug (4) feature (4) documentation (1) upkeep (1) Epic (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 280 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 8
  • Total maintainers: 1
cran.r-project.org: gibasa

An Alternative 'Rcpp' Wrapper of 'MeCab'

  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 280 Last month
Rankings
Stargazers count: 15.1%
Forks count: 21.0%
Dependent repos count: 23.8%
Dependent packages count: 28.7%
Average: 29.4%
Downloads: 58.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • Matrix * imports
  • Rcpp * imports
  • RcppParallel * imports
  • audubon >= 0.3.0 imports
  • dplyr * imports
  • purrr * imports
  • rlang >= 0.4.11 imports
  • stringi * imports
  • utils * imports
  • roxygen2 * suggests
  • testthat >= 3.0.0 suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/rhub.yaml actions
  • r-hub/rhub2/actions/rhub-checkout v1 composite
  • r-hub/rhub2/actions/rhub-platform-info v1 composite
  • r-hub/rhub2/actions/rhub-run-check v1 composite
  • r-hub/rhub2/actions/rhub-setup v1 composite
  • r-hub/rhub2/actions/rhub-setup-deps v1 composite
  • r-hub/rhub2/actions/rhub-setup-r v1 composite