diff --git a/website/src/component/container/App/App.js b/website/src/component/container/App/App.js index b126d5f..5458030 100644 --- a/website/src/component/container/App/App.js +++ b/website/src/component/container/App/App.js @@ -4,6 +4,7 @@ const React = require("react"); import InputForm from "../../project/InputForm/InputForm"; import AnalyzedTable from "../../project/AnalyzedTable/AnalyzedTable"; import AnalyzedJSONField from "../../project/AnalyzedJSONField/AnalyzedJSONField"; +import SideEffectLocationHash from "../../project/SideEffectLocationHash/SideEffectLocationHash"; import AppLocator from "../../../AppLocator"; import UpdateAnalyzedTableUseCase from "../../../js/use-case/analyzer/UpdateAnalyzedTableUseCase"; export default class App extends React.Component { @@ -28,13 +29,15 @@ export default class App extends React.Component { * @type {AnalyzerState} */ const analyzer = this.state.analyzer; + const currentText = analyzer.currentText; const outputJSON = analyzer.outputJSON; const onSubmit = (text) => { AppLocator.context.useCase(UpdateAnalyzedTableUseCase.create()).execute(text); }; return
+
- +
diff --git a/website/src/component/container/AppBootStrap.js b/website/src/component/container/AppBootStrap.js index ed55874..ac81dec 100644 --- a/website/src/component/container/AppBootStrap.js +++ b/website/src/component/container/AppBootStrap.js @@ -8,7 +8,8 @@ import InitializeUseCase from "../../js/use-case/InitializeUseCase"; const AppLoading = LoadingContainer(App); export default class AppBootStrap extends React.Component { render() { - const promise = AppLocator.context.useCase(InitializeUseCase.create()).execute(); + const hash = location.hash.slice(1); + const promise = AppLocator.context.useCase(InitializeUseCase.create()).execute({hash}); return ; } } diff --git a/website/src/component/project/InputForm/InputForm.js b/website/src/component/project/InputForm/InputForm.js index 2e38e47..1517283 100644 --- a/website/src/component/project/InputForm/InputForm.js +++ b/website/src/component/project/InputForm/InputForm.js @@ -18,7 +18,8 @@ export default class InputForm extends React.Component {
this.input = c} className="InputForm-input input is-expanded" - type="text" name="name" size="20"/> + type="text" name="name" size="20" + defaultValue={this.props.defaultValue ? this.props.defaultValue: null}/>

diff --git a/website/src/component/project/SideEffectLocationHash/SideEffectLocationHash.js b/website/src/component/project/SideEffectLocationHash/SideEffectLocationHash.js new file mode 100644 index 0000000..0698377 --- /dev/null +++ b/website/src/component/project/SideEffectLocationHash/SideEffectLocationHash.js @@ -0,0 +1,25 @@ +// LICENSE : MIT +"use strict"; +const React = require("react"); +export default class SideEffectLocationHash extends React.Component { + + shouldComponentUpdate(nextProps, nextState) { + return nextProps.text !== undefined && nextProps.text.length > 0; + } + + render() { + this._updateHash(this.props.text); + return null; + } + + + _updateHash(text) { + if (text && text.length > 0) { + location.hash = text; + } + } +} +SideEffectLocationHash.propTypes = { + updateText: React.PropTypes.func, + text: React.PropTypes.string +}; diff --git a/website/src/js/domain/analyzer/Analyzer.js b/website/src/js/domain/analyzer/Analyzer.js index 43250ee..0f08f37 100644 --- a/website/src/js/domain/analyzer/Analyzer.js +++ b/website/src/js/domain/analyzer/Analyzer.js @@ -1,5 +1,6 @@ // LICENSE : MIT "use strict"; +import Token from "../token/Token"; export default class Analyzer { constructor({tokenizer}) { this.currentText = ""; @@ -9,6 +10,8 @@ export default class Analyzer { analyze(text) { this.currentText = text; - this.analyzedTokens = this.tokenizer.tokenize(text); + this.analyzedTokens = this.tokenizer.tokenize(text).map(rawToken => { + return new Token(rawToken); + }); } } \ No newline at end of file diff --git a/website/src/js/domain/token/Token.js b/website/src/js/domain/token/Token.js index d7aa7ee..9314a5d 100644 --- a/website/src/js/domain/token/Token.js +++ b/website/src/js/domain/token/Token.js @@ -29,4 +29,38 @@ export default class Token { // 発音 this.pronunciation = object.pronunciation; } + + toJSON() { + const basicResults = { + // 表層形 + surface_form: this.surface_form, + // 品詞 + pos: this.pos, + // 品詞細分類1 + pos_detail_1: this.pos_detail_1, + // 品詞細分類2 + pos_detail_2: this.pos_detail_2, + // 品詞細分類3 + pos_detail_3: this.pos_detail_3, + // 活用型 + conjugated_type: this.conjugated_type, + // 活用形 + conjugated_form: this.conjugated_form, + // 基本形 + basic_form: this.basic_form, + // 読み + reading: this.reading, + // 発音 + pronunciation: this.pronunciation + }; + const filteredResult = {}; + Object.keys(basicResults).forEach(key => { + const value = basicResults[key]; + if (!value || value.length === 0) { + return; + } + filteredResult[key] = value; + }); + return filteredResult; + } } \ No newline at end of file diff --git a/website/src/js/store/analyzer/AnalyzerState.js b/website/src/js/store/analyzer/AnalyzerState.js index aebeeb6..369b599 100644 --- a/website/src/js/store/analyzer/AnalyzerState.js +++ b/website/src/js/store/analyzer/AnalyzerState.js @@ -7,6 +7,7 @@ export default class AnalyzerState extends ReduceState { */ constructor({analyzer = {}} = {}) { super(); + this.currentText = analyzer.currentText; this.tokens = analyzer.analyzedTokens || []; } diff --git a/website/src/js/use-case/InitializeUseCase.js b/website/src/js/use-case/InitializeUseCase.js index eb9ce9b..d4814c4 100644 --- a/website/src/js/use-case/InitializeUseCase.js +++ b/website/src/js/use-case/InitializeUseCase.js @@ -3,7 +3,8 @@ import {UseCase} from "almin"; import analyzedRepository from "../infra/repository/AnalyzerRepository"; import AnalyzerFactory from "../domain/analyzer/AnalyzerFactory"; -export default class UpdateAnalyzedTableUseCase extends UseCase { +import UpdateAnalyzedTableUseCase from "./analyzer/UpdateAnalyzedTableUseCase"; +export default class InitializeUseCase extends UseCase { static create() { return new this({ analyzedRepository @@ -18,12 +19,12 @@ export default class UpdateAnalyzedTableUseCase extends UseCase { this.analyzedRepository = analyzedRepository; } - /** - * @param {string} text - */ - execute(text) { - AnalyzerFactory.create().then((analyzer) => { + execute({hash}) { + const defaultText = hash || "日本語の文章を解析します。"; + return AnalyzerFactory.create().then((analyzer) => { this.analyzedRepository.save(analyzer); + const initializeAnalyzedText = new UpdateAnalyzedTableUseCase({analyzedRepository: this.analyzedRepository}); + return this.context.useCase(initializeAnalyzedText).execute(defaultText); }); } } \ No newline at end of file