This is an automated email from the ASF dual-hosted git repository. ifropc pushed a commit to branch NLPCRAFT-91 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 5cf788839e0798e083f891ca873ca04828e41cba Author: Ifropc <[email protected]> AuthorDate: Sun Dec 20 23:25:17 2020 -0800 NLPCRAFT-91: Initial model for weather command --- .../org/apache/nlpcraft/example/MinecraftModel.kt | 19 ++---- .../src/main/resources/minecraft.yaml | 48 +++++++++---- nlpcraft-examples/src/main/resources/nlpcraft.conf | 78 ++++++++++++++++++++++ 3 files changed, 121 insertions(+), 24 deletions(-) diff --git a/nlpcraft-examples/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt b/nlpcraft-examples/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt index 4f5593f..76cedd9 100644 --- a/nlpcraft-examples/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt +++ b/nlpcraft-examples/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt @@ -21,18 +21,13 @@ package org.apache.nlpcraft.example import org.apache.nlpcraft.model.* class MinecraftModel : NCModelFileAdapter("minecraft.yaml") { + @NCIntentRef("weatherIntent") + @Suppress("unused") + fun onMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult { + if (ctx.isAmbiguous) { + throw NCRejection("Ambiguous request") + } - @NCIntentRef("intentId") - fun onMatch(ctx: NCIntentMatch, @NCIntentTerm("element") tok: NCToken): NCResult { - // TODO: add the actual intent logic here. - - // As a placeholder - just return an echo string. - return NCResult.text( - String.format( - "Word `%s` found in text: `%s`", - tok.originalText, - ctx.context.request.normalizedText - ) - ) + return NCResult.text("weather ${tok.id}") } } diff --git a/nlpcraft-examples/src/main/resources/minecraft.yaml b/nlpcraft-examples/src/main/resources/minecraft.yaml index 0306294..872bf90 100644 --- a/nlpcraft-examples/src/main/resources/minecraft.yaml +++ b/nlpcraft-examples/src/main/resources/minecraft.yaml @@ -1,21 +1,45 @@ -# Mandatory model configuration. -id: minecraft +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +id: nlpcraft.minecraft.ex name: Minecraft Model version: '1.0' description: Minecraft Model. -# List of macros, if any. -macros: - - name: "<MY_MACRO>" - macro: "{word1|word2}" - -# List of model elements. elements: - - id: elementId - description: An element. + - id: rain + description: Set rain weather + groups: + - weather + synonyms: + - "{rain|rainy}" + - id: sun + description: Set sunny weather + groups: + - weather + synonyms: + - "{sun|sunny|clear sky}" + - id: storm + description: Set stormy weather + groups: + - weather synonyms: - - "{some|*} <MY_MACRO>" + - "{thunder|storm|stormy}" # List of model intents. intents: - - intent=intentId term(element)={id == 'elementId'} + - intent=weatherIntent term(arg)={groups @@ 'weather'} diff --git a/nlpcraft-examples/src/main/resources/nlpcraft.conf b/nlpcraft-examples/src/main/resources/nlpcraft.conf new file mode 100644 index 0000000..f9b4a44 --- /dev/null +++ b/nlpcraft-examples/src/main/resources/nlpcraft.conf @@ -0,0 +1,78 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +nlpcraft { + server { + lifecycle = "" + database { + jdbc { + url = "jdbc:ignite:thin://127.0.0.1/nlpcraft" + driver = org.apache.ignite.IgniteJdbcThinDriver + } + igniteDbInitialize = false + c3p0 { + maxStatements = 180 + pool { + initSize = 10 + minSize = 1 + maxSize = 50 + acquireIncrement = 2 + } + } + } + rest { + host = "0.0.0.0" + port = 8081 + apiImpl = "org.apache.nlpcraft.server.rest.NCBasicRestApi" + } + user { + pwdPoolBlowup = 3 + timeoutScannerFreqMins = 1 + accessTokenExpireTimeoutMins = 60 + } + probe { + links { + upLink = "0.0.0.0:8201" # Server to probe data pipe. + downLink = "0.0.0.0:8202" # Probe to server data pipe. + } + pingTimeoutMs = 2000 + soTimeoutMs = 5000 + reconnectTimeoutMs = 5000 + } + datesFormatStyle = MDY + tokenProviders = "nlpcraft" + ctxword.url="http://localhost:5000" + } + + nlpEngine = "opennlp" + + extConfig { + extUrl = "https://github.com/apache/incubator-nlpcraft/raw/master/external" + checkMd5 = true + } + probe { + id = "extended.examples" + token = "3141592653589793" + upLink = "0.0.0.0:8201" # Server to probe data pipe. + downLink = "0.0.0.0:8202" # Probe to server data pipe. + jarsFolder = null + models = + """org.apache.nlpcraft.example.MinecraftModel""" + lifecycle = "" + resultMaxSizeBytes = 1048576 + } +}
