morpheme-match
Advanced tools
Comparing version 1.2.1 to 2.0.0
@@ -1,6 +0,5 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
function matchToken(token, expectShape) { | ||
return Object.keys(expectShape).every(function (key) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function matchToken(token, expectedToken) { | ||
return Object.keys(expectedToken).every(function (key) { | ||
// Ignore start with _ key | ||
@@ -10,6 +9,8 @@ if (key[0] === "_") { | ||
} | ||
var actualValue = token[key]; | ||
var expectedKey = key; | ||
var actualValue = token[expectedKey]; | ||
// support multiple value | ||
// "pos": ["名詞", "副詞"] | ||
var expectedValues = Array.isArray(expectShape[key]) ? expectShape[key] : [expectShape[key]]; | ||
var expectedValue = expectedToken[expectedKey]; | ||
var expectedValues = Array.isArray(expectedValue) ? expectedValue : [expectedValue]; | ||
return expectedValues.some(function (expectedValue) { | ||
@@ -20,16 +21,13 @@ return actualValue === expectedValue; | ||
} | ||
/** | ||
* Create matcher function that return { match : true , tokens []} if match the `token`. | ||
* @param {Object[]} matchedTokens | ||
* @returns {function(token:Object)} | ||
*/ | ||
module.exports = function createTokenMatcher(matchedTokens) { | ||
function createTokenMatcher(expectedTokens) { | ||
var currentTokenPosition = 0; | ||
var tokenCount = matchedTokens.length; | ||
var tokenCount = expectedTokens.length; | ||
var matchTokens = []; | ||
var matchSkipped = []; | ||
return function (token, index) { | ||
return function (token) { | ||
while (currentTokenPosition < tokenCount) { | ||
var expectedToken = matchedTokens[currentTokenPosition]; | ||
var expectedToken = expectedTokens[currentTokenPosition]; | ||
if (matchToken(token, expectedToken)) { | ||
@@ -40,6 +38,8 @@ matchTokens.push(token); | ||
break; | ||
} else if (expectedToken["_skippable"]) { | ||
} | ||
else if (expectedToken["_skippable"]) { | ||
currentTokenPosition += 1; | ||
matchSkipped.push(true); | ||
} else { | ||
} | ||
else { | ||
// reset position | ||
@@ -67,6 +67,9 @@ matchTokens.length = 0; | ||
return { | ||
match: false | ||
match: false, | ||
tokens: [], | ||
skipped: [] | ||
}; | ||
}; | ||
}; | ||
} | ||
exports.createTokenMatcher = createTokenMatcher; | ||
//# sourceMappingURL=morpheme-match.js.map |
{ | ||
"name": "morpheme-match", | ||
"version": "2.0.0", | ||
"description": "match function that match token(形態素解析) with sentence.", | ||
"keywords": [ | ||
"japanese", | ||
"morpheme", | ||
"text", | ||
"形態素" | ||
], | ||
"homepage": "https://github.com/azu/morpheme-match", | ||
"bugs": { | ||
"url": "https://github.com/azu/morpheme-match/issues" | ||
}, | ||
"repository": { | ||
@@ -7,9 +19,4 @@ "type": "git", | ||
}, | ||
"license": "MIT", | ||
"author": "azu", | ||
"email": "azuciao@gmail.com", | ||
"homepage": "https://github.com/azu/morpheme-match", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/azu/morpheme-match/issues" | ||
}, | ||
"files": [ | ||
@@ -19,4 +26,4 @@ "src/", | ||
], | ||
"version": "1.2.1", | ||
"main": "lib/morpheme-match.js", | ||
"types": "lib/morpheme-match.d.ts", | ||
"directories": { | ||
@@ -26,26 +33,19 @@ "test": "test" | ||
"scripts": { | ||
"test": "mocha test/", | ||
"build": "NODE_ENV=production babel src --out-dir lib --source-maps", | ||
"watch": "babel src --out-dir lib --watch --source-maps", | ||
"build": "cross-env NODE_ENV=production tsc -p .", | ||
"build:website": "cd website && npm i && npm run build", | ||
"prepublish": "npm run --if-present build", | ||
"build:website": "cd website && npm i && npm run build" | ||
"test": "mocha \"test/**/*.{js,ts}\"", | ||
"watch": "tsc -p . --watch" | ||
}, | ||
"keywords": [ | ||
"morpheme", | ||
"形態素", | ||
"japanese", | ||
"text" | ||
], | ||
"description": "match function that match token(形態素解析) with sentence.", | ||
"devDependencies": { | ||
"@alrra/travis-scripts": "^3.0.1", | ||
"babel-cli": "^6.9.0", | ||
"babel-loader": "^6.2.4", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-jsdoc-to-assert": "^2.0.1", | ||
"babel-preset-power-assert": "^1.0.0", | ||
"babel-register": "^6.9.0", | ||
"mocha": "^2.5.3", | ||
"power-assert": "^1.4.1" | ||
} | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.0.7", | ||
"cross-env": "^5.2.0", | ||
"mocha": "^6.1.4", | ||
"ts-node": "^8.2.0", | ||
"ts-node-test-register": "^8.0.1", | ||
"typescript": "^3.5.1" | ||
}, | ||
"email": "azuciao@gmail.com", | ||
"gitHead": "3c3aa522a214e319eac7bfd7817dbd23b7a56cb0" | ||
} |
@@ -1,2 +0,2 @@ | ||
# morpheme-match [![Build Status](https://travis-ci.org/azu/morpheme-match.svg?branch=master)](https://travis-ci.org/azu/morpheme-match) | ||
# morpheme-match | ||
@@ -7,8 +7,2 @@ morpheme-match provide match function that match token with sentence. | ||
## Online Demo | ||
[![Online demo site](https://monosnap.com/file/URqDU4n0lsd23ZdDtWumhMNCCgvpSy.png)](https://azu.github.io/morpheme-match/) | ||
Please go to https://azu.github.io/morpheme-match/ | ||
## Install | ||
@@ -32,4 +26,4 @@ | ||
```js | ||
const createTokenMatcher = require("morpheme-match"); | ||
const expectToken = createTokenMatcher([ | ||
import {createTokenMatcher} from "morpheme-match"; | ||
const matchToken = createTokenMatcher([ | ||
{ | ||
@@ -100,3 +94,3 @@ "surface_form": "かも", | ||
const result = tokens.some(token => { | ||
const {match} = expectToken(token); | ||
const {match} = matchToken(token); | ||
return match; | ||
@@ -113,3 +107,3 @@ }); | ||
const result = tokens.some(token => { | ||
const {match, tokens, skipped} = expectToken(token); | ||
const {match, tokens, skipped} = matchToken(token); | ||
resultTokens = tokens; | ||
@@ -138,3 +132,3 @@ return match; | ||
```js | ||
const expectToken = createTokenMatcher([ | ||
const matchToken = createTokenMatcher([ | ||
{ | ||
@@ -160,3 +154,3 @@ "surface_form": "かも", | ||
```js | ||
const expectToken = createTokenMatcher([ | ||
const matchToken = createTokenMatcher([ | ||
{ | ||
@@ -163,0 +157,0 @@ "surface_form": "かも", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16812
7
8
208
200
1