Skip to content

Commit

Permalink
refactor: convert to ts/esm
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jan 16, 2025
1 parent f682ade commit 5edad3b
Show file tree
Hide file tree
Showing 16 changed files with 2,210 additions and 3,353 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

5 changes: 0 additions & 5 deletions .mocharc.json

This file was deleted.

67 changes: 32 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@

```js
"use strict";
const isDearu = require("analyze-desumasu-dearu").isDearu;
const isDesumasu = require("analyze-desumasu-dearu").isDesumasu;
const analyze = require("analyze-desumasu-dearu").analyze;
const analyzeDearu = require("analyze-desumasu-dearu").analyzeDearu;
const analyzeDesumasu = require("analyze-desumasu-dearu").analyzeDesumasu;
const text = "昨日はいい天気であったのだが、今日は悪天候です。";
analyze(text).then(results => {
import { isDearu, isDesumasu, analyze, analyzeDearu, analyzeDesumasu } from "analyze-desumasu-dearu";
analyze(text).then((results) => {
console.log("==である==");
console.log(results.filter(isDearu));
console.log("==ですます==");
Expand All @@ -34,7 +29,7 @@ Result to
value: 'であった',
surface: 'で',
index: 7,
token:
token:
{ word_id: 305030,
word_type: 'KNOWN',
word_position: 8,
Expand All @@ -52,7 +47,7 @@ Result to
value: 'だが、',
surface: 'だ',
index: 12,
token:
token:
{ word_id: 305000,
word_type: 'KNOWN',
word_position: 13,
Expand All @@ -71,7 +66,7 @@ Result to
value: 'です。',
surface: 'です',
index: 21,
token:
token:
{ word_id: 305080,
word_type: 'KNOWN',
word_position: 22,
Expand All @@ -91,8 +86,8 @@ Result to

`text`から敬体(ですます調)と常体(である調)を取り出した結果を返します

- `options`
- `ignoreConjunction`: 無視オプションを指定できます
- `options`
- `ignoreConjunction`: 無視オプションを指定できます

```js
/**
Expand All @@ -104,28 +99,30 @@ const defaultOptions = {
// e.g.) 今日はいい天気であるが明日はどうなるかは分からない。
ignoreConjunction: false
};
````
```

```js
// AnalyzedResultObjectの配列
[{
// 文体を含んだ内容 - なんとなくいい感じの部分までを繋げた文字列
// e.g.) "です。"
value: string,
// 該当するtoken文字
// e.g.) "です"
surface: string,
// textの先頭からの位置(start with 0)
index: number,
// kuromoji.jsのtokenオブジェクトそのもの https://github.com/takuyaa/kuromoji.js#api
// surfaceやindexはこのtokenから算出
token: AnalyzedToken
}]
[
{
// 文体を含んだ内容 - なんとなくいい感じの部分までを繋げた文字列
// e.g.) "です。"
value: string,
// 該当するtoken文字
// e.g.) "です"
surface: string,
// textの先頭からの位置(start with 0)
index: number,
// kuromoji.jsのtokenオブジェクトそのもの https://github.com/takuyaa/kuromoji.js#api
// surfaceやindexはこのtokenから算出
token: AnalyzedToken
}
];
```

### `analyzeDesumasu(text, options): Promise.<AnalyzedResultObject[]>`
`text`に含まれる文の敬体(ですます調)を解析して、AnalyzedResultObjectの配列を返します

`text`に含まれる文の敬体(ですます調)を解析して、AnalyzedResultObject の配列を返します

内部的には`analyze()`を使っています。

Expand All @@ -137,16 +134,16 @@ const defaultOptions = {
* @return {Promise.<AnalyzedResultObject[]>}
*/
export function analyzeDesumasu(text, options = defaultOptions) {
return analyze(text, options).then(results => results.filter(isDesumasu));
return analyze(text, options).then((results) => results.filter(isDesumasu));
}
```

### `analyzeDearu(text, options): Promise.<AnalyzedResultObject[]>`

常体(である調)を解析してAnalyzedResultObjectの配列を返します
常体(である調)を解析して AnalyzedResultObject の配列を返します

- `options`
- `ignoreConjunction`: 無視オプションを指定できます。
- `options`
- `ignoreConjunction`: 無視オプションを指定できます。

```js
/**
Expand All @@ -158,7 +155,7 @@ const defaultOptions = {
// e.g.) 今日はいい天気であるが明日はどうなるかは分からない。
ignoreConjunction: false
};
````
```

内部的には`analyze()`を使っています。

Expand All @@ -170,7 +167,7 @@ const defaultOptions = {
* @return {Promise.<AnalyzedResultObject[]>}
*/
export function analyzeDearu(text, options = defaultOptions) {
return analyze(text, options).then(results => results.filter(isDearu))
return analyze(text, options).then((results) => results.filter(isDearu));
}
```

Expand Down
37 changes: 0 additions & 37 deletions example/index.js

This file was deleted.

14 changes: 0 additions & 14 deletions example/package.json

This file was deleted.

57 changes: 57 additions & 0 deletions module/analyze.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { KuromojiToken } from "kuromojin";
/**
* Analyzed result Object
*/
export type AnalyzedResultObject = {
type: string;
value: string;
surface: string;
token: KuromojiToken;
index: number;
};
export type AnalyzeOptions = {
/**
* 接続詞を分析対象から除外するかどうか
*/
ignoreConjunction: boolean;
};
/**
* Type enum
* @type {{desu: string, dearu: string}}
* @example
* analyze(text).filter(results => results.type === Types.desu);
*/
export declare const Types: {
desu: string;
masu: string;
dearu: string;
};
/**
* @param {AnalyzedResultObject} resultObject
* @returns {boolean}
*/
export declare function isDesumasu({ type }: AnalyzedResultObject): boolean;
/**
* @param {AnalyzedResultObject} resultObject
* @returns {boolean}
*/
export declare function isDearu({ type }: AnalyzedResultObject): boolean;
/**
* `text`から敬体(ですます調)と常体(である調)を取り出した結果を返します。
*/
export declare function analyze(text: string, options?: AnalyzeOptions): Promise<AnalyzedResultObject[]>;
/**
* `text` の敬体(ですます調)について解析し、敬体(ですます調)のトークン情報を返します。
* @param {string} text
* @param {Object} options
* @return {Promise.<AnalyzedResultObject[]>}
*/
export declare function analyzeDesumasu(text: string, options?: AnalyzeOptions): Promise<AnalyzedResultObject[]>;
/**
* `text` の常体(である調)について解析し、常体(である調)のトークン情報を返します。
* @param {string} text
* @param {Object} options
* @return {Promise.<AnalyzedResultObject[]>}
*/
export declare function analyzeDearu(text: string, options?: AnalyzeOptions): Promise<AnalyzedResultObject[]>;
//# sourceMappingURL=analyze.d.ts.map
1 change: 1 addition & 0 deletions module/analyze.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 4 additions & 31 deletions src/analyze.js → module/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions module/analyze.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions module/tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"root":["../src/analyze.ts"],"version":"5.7.3"}
Loading

0 comments on commit 5edad3b

Please sign in to comment.