├── .asf.yaml
├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── DISCLAIMER-WIP
├── LICENSE
├── NOTICE
├── README.md
├── assembly.xml
├── bin
├── MAVEN-RELEASE.md
└── prepare.sh
├── bindist
├── LICENSE
└── NOTICE
├── build.sbt
├── nlpcraft-examples
├── calculator
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── scala
│ │ │ └── org
│ │ │ └── apache
│ │ │ └── nlpcraft
│ │ │ └── examples
│ │ │ └── time
│ │ │ └── CalculatorModel.scala
│ │ └── test
│ │ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── examples
│ │ └── time
│ │ └── CalculatorModelSpec.scala
├── lightswitch-fr
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── resources
│ │ │ └── lightswitch_model_fr.yaml
│ │ └── scala
│ │ │ └── org
│ │ │ └── apache
│ │ │ └── nlpcraft
│ │ │ └── examples
│ │ │ └── lightswitch
│ │ │ ├── LightSwitchFrModel.scala
│ │ │ └── nlp
│ │ │ ├── entity
│ │ │ └── parser
│ │ │ │ └── NCFrSemanticEntityParser.scala
│ │ │ └── token
│ │ │ ├── enricher
│ │ │ ├── NCFrLemmaPosTokenEnricher.scala
│ │ │ └── NCFrStopWordsTokenEnricher.scala
│ │ │ └── parser
│ │ │ └── NCFrTokenParser.scala
│ │ └── test
│ │ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── examples
│ │ └── lightswitch
│ │ └── LightSwitchFrModelSpec.scala
├── lightswitch-ru
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── resources
│ │ │ └── lightswitch_model_ru.yaml
│ │ └── scala
│ │ │ └── org
│ │ │ └── apache
│ │ │ └── nlpcraft
│ │ │ └── examples
│ │ │ └── lightswitch
│ │ │ ├── LightSwitchRuModel.scala
│ │ │ └── nlp
│ │ │ ├── entity
│ │ │ └── parser
│ │ │ │ └── NCRuSemanticEntityParser.scala
│ │ │ └── token
│ │ │ ├── enricher
│ │ │ ├── NCRuLemmaPosTokenEnricher.scala
│ │ │ └── NCRuStopWordsTokenEnricher.scala
│ │ │ └── parser
│ │ │ └── NCRuTokenParser.scala
│ │ └── test
│ │ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── examples
│ │ └── lightswitch
│ │ └── LightSwitchRuModelSpec.scala
├── lightswitch
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── resources
│ │ │ └── lightswitch_model.yaml
│ │ └── scala
│ │ │ └── org
│ │ │ └── apache
│ │ │ └── nlpcraft
│ │ │ └── examples
│ │ │ └── lightswitch
│ │ │ └── LightSwitchModel.scala
│ │ └── test
│ │ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── examples
│ │ └── lightswitch
│ │ └── LightSwitchModelSpec.scala
├── pizzeria
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── resources
│ │ │ └── pizzeria_model.yaml
│ │ └── scala
│ │ │ └── org
│ │ │ └── apache
│ │ │ └── nlpcraft
│ │ │ └── examples
│ │ │ └── pizzeria
│ │ │ ├── PizzeriaModel.scala
│ │ │ ├── PizzeriaOrder.scala
│ │ │ └── components
│ │ │ ├── PizzeriaModelPipeline.scala
│ │ │ ├── PizzeriaOrderMapper.scala
│ │ │ └── PizzeriaOrderValidator.scala
│ │ └── test
│ │ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── examples
│ │ └── pizzeria
│ │ ├── PizzeriaModelSpec.scala
│ │ └── cli
│ │ ├── PizzeriaModelClientCli.scala
│ │ └── PizzeriaModelServer.scala
└── time
│ ├── README.md
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── resources
│ │ ├── cities_timezones.txt
│ │ └── time_model.yaml
│ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── examples
│ │ └── time
│ │ ├── TimeModel.scala
│ │ └── utils
│ │ ├── cities
│ │ └── CitiesDataProvider.scala
│ │ └── keycdn
│ │ └── GeoManager.scala
│ └── test
│ └── scala
│ └── org
│ └── apache
│ └── nlpcraft
│ └── examples
│ └── time
│ └── TimeModelSpec.scala
├── nlpcraft-stanford
├── pom.xml
└── src
│ ├── main
│ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ └── nlp
│ │ └── stanford
│ │ ├── NCStanfordNLPEntityParser.scala
│ │ └── NCStanfordNLPTokenParser.scala
│ └── test
│ └── scala
│ └── org
│ └── apache
│ └── nlpcraft
│ └── nlp
│ └── stanford
│ ├── NCStanfordNLPEntityParserSpec.scala
│ ├── NCStanfordNLPTokenParserSpec.scala
│ └── util
│ └── NCTestConfig.scala
├── nlpcraft
├── pom.xml
└── src
│ ├── main
│ ├── resources
│ │ ├── log4j2.xml
│ │ ├── moby
│ │ │ └── 354984si.ngl
│ │ └── stopwords
│ │ │ └── en_stop_words.txt
│ └── scala
│ │ └── org
│ │ └── apache
│ │ └── nlpcraft
│ │ ├── NCContext.scala
│ │ ├── NCConversation.scala
│ │ ├── NCCuration.scala
│ │ ├── NCDialogFlowItem.scala
│ │ ├── NCEntity.scala
│ │ ├── NCEntityEnricher.scala
│ │ ├── NCEntityMapper.scala
│ │ ├── NCEntityParser.scala
│ │ ├── NCEntityValidator.scala
│ │ ├── NCException.scala
│ │ ├── NCGlobals.scala
│ │ ├── NCIntentMatch.scala
│ │ ├── NCIntentSkip.scala
│ │ ├── NCLifecycle.scala
│ │ ├── NCMatchedCallback.scala
│ │ ├── NCModel.scala
│ │ ├── NCModelClient.scala
│ │ ├── NCModelConfig.scala
│ │ ├── NCPipeline.scala
│ │ ├── NCPipelineBuilder.scala
│ │ ├── NCPropertyMap.scala
│ │ ├── NCPropertyMapAdapter.scala
│ │ ├── NCRejection.scala
│ │ ├── NCRequest.scala
│ │ ├── NCResult.scala
│ │ ├── NCResultType.scala
│ │ ├── NCToken.scala
│ │ ├── NCTokenEnricher.scala
│ │ ├── NCTokenParser.scala
│ │ ├── NCTokenValidator.scala
│ │ ├── NCVariant.scala
│ │ ├── NCVariantFilter.scala
│ │ ├── annotations
│ │ ├── NCIntent.java
│ │ ├── NCIntentObject.java
│ │ ├── NCIntentRef.java
│ │ └── NCIntentTerm.java
│ │ ├── internal
│ │ ├── antlr4
│ │ │ ├── NCCompilerErrorHolder.scala
│ │ │ └── NCCompilerUtils.scala
│ │ ├── ascii
│ │ │ └── NCAsciiTable.scala
│ │ ├── conversation
│ │ │ ├── NCConversationData.scala
│ │ │ └── NCConversationManager.scala
│ │ ├── dialogflow
│ │ │ └── NCDialogFlowManager.scala
│ │ ├── impl
│ │ │ ├── NCModelPipelineHelper.java
│ │ │ ├── NCModelPipelineManager.scala
│ │ │ └── NCModelScanner.scala
│ │ ├── intent
│ │ │ ├── NCIDLContext.scala
│ │ │ ├── NCIDLEntity.scala
│ │ │ ├── NCIDLFunction.scala
│ │ │ ├── NCIDLIntent.scala
│ │ │ ├── NCIDLIntentOptions.scala
│ │ │ ├── NCIDLStack.scala
│ │ │ ├── NCIDLTerm.scala
│ │ │ ├── compiler
│ │ │ │ ├── NCIDLCodeGenerator.scala
│ │ │ │ ├── NCIDLCompiler.scala
│ │ │ │ └── antlr4
│ │ │ │ │ ├── NCIDL.g4
│ │ │ │ │ ├── NCIDL.interp
│ │ │ │ │ ├── NCIDL.tokens
│ │ │ │ │ ├── NCIDLBaseListener.java
│ │ │ │ │ ├── NCIDLLexer.interp
│ │ │ │ │ ├── NCIDLLexer.java
│ │ │ │ │ ├── NCIDLLexer.tokens
│ │ │ │ │ ├── NCIDLListener.java
│ │ │ │ │ └── NCIDLParser.java
│ │ │ └── matcher
│ │ │ │ └── NCIntentSolverManager.scala
│ │ ├── makro
│ │ │ ├── NCMacroCompiler.scala
│ │ │ ├── NCMacroParser.scala
│ │ │ └── antlr4
│ │ │ │ ├── NCMacroDsl.g4
│ │ │ │ ├── NCMacroDsl.interp
│ │ │ │ ├── NCMacroDsl.tokens
│ │ │ │ ├── NCMacroDslBaseListener.java
│ │ │ │ ├── NCMacroDslLexer.interp
│ │ │ │ ├── NCMacroDslLexer.java
│ │ │ │ ├── NCMacroDslLexer.tokens
│ │ │ │ ├── NCMacroDslListener.java
│ │ │ │ └── NCMacroDslParser.java
│ │ ├── util
│ │ │ ├── NCResourceReader.scala
│ │ │ └── NCUtils.scala
│ │ └── version
│ │ │ └── NCVersion.scala
│ │ └── nlp
│ │ ├── enrichers
│ │ ├── NCBracketsTokenEnricher.scala
│ │ ├── NCDictionaryTokenEnricher.scala
│ │ ├── NCEnStopWordsTokenEnricher.scala
│ │ ├── NCOpenNLPTokenEnricher.scala
│ │ ├── NCQuotesTokenEnricher.scala
│ │ ├── NCSwearWordsTokenEnricher.scala
│ │ └── impl
│ │ │ └── NCEnStopWordGenerator.scala
│ │ ├── parsers
│ │ ├── NCNLPEntityParser.scala
│ │ ├── NCOpenNLPEntityParser.scala
│ │ ├── NCOpenNLPTokenParser.scala
│ │ ├── NCSemanticElement.scala
│ │ ├── NCSemanticEntityParser.scala
│ │ └── impl
│ │ │ ├── NCSemanticSourceReader.scala
│ │ │ ├── NCSemanticSynonym.scala
│ │ │ └── NCSemanticSynonymsProcessor.scala
│ │ └── stemmer
│ │ ├── NCEnStemmer.scala
│ │ └── NCStemmer.scala
│ └── test
│ ├── resources
│ ├── log4j2.xml
│ ├── models
│ │ ├── alarm_model.json
│ │ └── lightswitch_model.yaml
│ └── scan
│ │ └── idl.idl
│ └── scala
│ └── org
│ └── apache
│ └── nlpcraft
│ ├── internal
│ ├── conversation
│ │ ├── NCConversationManagerSpec.scala
│ │ ├── NCConversationSpec.scala
│ │ ├── NCConversationSpec2.scala
│ │ └── NCConversationTimeoutSpec.scala
│ ├── dialogflow
│ │ └── NCDialogFlowManagerSpec.scala
│ ├── impl
│ │ ├── NCModelCallbacksSpec.scala
│ │ ├── NCModelClientSpec.scala
│ │ ├── NCModelClientSpec2.scala
│ │ ├── NCModelClientSpec3.scala
│ │ ├── NCModelClientSpec4.scala
│ │ ├── NCModelPingPongSpec.scala
│ │ ├── NCPipelineManagerSpec.scala
│ │ └── scan
│ │ │ ├── NCModelIntentsInvalidArgsSpec.scala
│ │ │ ├── NCModelIntentsInvalidIntentsSpec.scala
│ │ │ ├── NCModelIntentsNestedSpec.scala
│ │ │ ├── NCModelIntentsSpec.scala
│ │ │ └── NCTestModelScala.scala
│ ├── intent
│ │ └── compiler
│ │ │ ├── NCIDLCompilerSpec.scala
│ │ │ ├── NCIDLFragmentsOverridingSpec.scala
│ │ │ ├── NCIDLFragmentsOverridingSpec2.scala
│ │ │ ├── NCIDLFragmentsSpec.scala
│ │ │ ├── functions
│ │ │ ├── NCIDLFunctions.scala
│ │ │ ├── NCIDLFunctionsCollections.scala
│ │ │ ├── NCIDLFunctionsDate.scala
│ │ │ ├── NCIDLFunctionsEntitiesUsed.scala
│ │ │ ├── NCIDLFunctionsEntity.scala
│ │ │ ├── NCIDLFunctionsMath.scala
│ │ │ ├── NCIDLFunctionsMeta.scala
│ │ │ ├── NCIDLFunctionsModel.scala
│ │ │ ├── NCIDLFunctionsOther.scala
│ │ │ ├── NCIDLFunctionsRequest.scala
│ │ │ ├── NCIDLFunctionsStat.scala
│ │ │ └── NCIDLFunctionsStrings.scala
│ │ │ ├── impl_level1.idl
│ │ │ ├── impl_level2.idl
│ │ │ └── test_ok.idl
│ └── util
│ │ ├── NCResourceSpec.scala
│ │ └── NCUtilsSpec.scala
│ └── nlp
│ ├── NCEntityEnricherSpec.scala
│ ├── NCEntityMapperSpec.scala
│ ├── NCEntityParserSpec.scala
│ ├── NCEntityValidatorSpec.scala
│ ├── NCTokenEnricherSpec.scala
│ ├── NCTokenValidatorSpec.scala
│ ├── NCVariantFilterSpec.scala
│ ├── enrichers
│ ├── NCBracketsTokenEnricherSpec.scala
│ ├── NCDictionaryTokenEnricherSpec.scala
│ ├── NCQuotesTokenEnricherSpec.scala
│ ├── NCStopWordsEnricherSpec.scala
│ ├── NCSwearWordsTokenEnricherSpec.scala
│ └── impl
│ │ └── NCStopWordsImplSpec.scala
│ ├── parsers
│ ├── NCNLPEntityParserSpec.scala
│ ├── NCOpenNLPEntityParserSpec.scala
│ ├── NCOpenNLPTokenParserSpec.scala
│ ├── NCSemanticEntityParserJsonSpec.scala
│ ├── NCSemanticEntityParserLemmaSpec.scala
│ ├── NCSemanticEntityParserSpec.scala
│ ├── NCSemanticEntityParserYamlSpec.scala
│ └── NCSemanticTestElement.scala
│ └── util
│ ├── NCTestConfig.scala
│ ├── NCTestEntity.scala
│ ├── NCTestModelAdapter.scala
│ ├── NCTestPipeline.scala
│ ├── NCTestRequest.scala
│ ├── NCTestResult.scala
│ ├── NCTestToken.scala
│ └── NCTestUtils.scala
├── pom.xml
├── project
├── build.properties
└── plugins.sbt
└── scaladoc
└── docroot.md
/.asf.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | # Metadata.
19 | github:
20 | description: "Apache NLPCraft - API to convert natural language into actions."
21 | homepage: https://nlpcraft.apache.org/
22 | enabled_merge_buttons:
23 | squash: true
24 | merge: true
25 | rebase: true
26 | features:
27 | wiki: false
28 | issues: false
29 | projects: false
30 | labels:
31 | - "java"
32 | - "scala"
33 | - "nlp"
34 | - "apache"
35 |
36 | # PR whitelist.
37 | jenkins:
38 | github_whitelist:
39 | - aradzinski
40 |
41 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | name: build
17 |
18 | on:
19 | push:
20 | branches:
21 | - master
22 | pull_request:
23 | branches:
24 | - master
25 |
26 | jobs:
27 | build:
28 | name: "Build on JDK ${{matrix.java}} (${{matrix.os}})"
29 |
30 | strategy:
31 | matrix:
32 | os: [ubuntu-latest, windows-latest]
33 | java: [11]
34 |
35 | runs-on: ${{matrix.os}}
36 |
37 | steps:
38 | - name: Checkout
39 | uses: actions/checkout@v2
40 |
41 | - name: Set up JDK
42 | uses: actions/setup-java@v1
43 | with:
44 | java-version: ${{matrix.java}}
45 |
46 | - name: Cache Maven packages
47 | uses: actions/cache@v1
48 | with:
49 | path: ~/.m2
50 | key: ${{runner.os}}-m2-${{hashFiles('**/pom.xml')}}
51 | restore-keys: ${{runner.os}}-m2
52 |
53 | - name: Build (Linux)
54 | if: ${{matrix.os == 'ubuntu-latest'}}
55 | run: 'mvn -B clean verify -P stanford-core,examples'
56 |
57 | - name: Build (Windows)
58 | if: ${{matrix.os == 'windows-latest'}}
59 | # Build only, no tests because of memory limits.
60 | run: 'mvn -B clean package -DskipTests=true -P stanford-core,examples'
61 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | **/*.iml
19 | *.iml
20 | .idea
21 | venv/
22 | target
23 | null
24 | out
25 | zips
26 | model.yaml
27 | model.json
28 | **/__pycache__
29 | **/data
30 | **/.ipynb_checkpoints/
31 |
32 | # OS generated files.
33 | #####################
34 | .DS_Store
35 | .DS_Store?
36 | ._*
37 | .Spotlight-V100
38 | .Trashes
39 | ehthumbs.db
40 | Thumbs.db
41 | .bsp/sbt.json
42 |
--------------------------------------------------------------------------------
/DISCLAIMER-WIP:
--------------------------------------------------------------------------------
1 | Apache NLPCraft is an effort undergoing incubation at The Apache Software Foundation (ASF),
2 | sponsored by the Apache Incubator. Incubation is required of all newly accepted projects
3 | until a further review indicates that the infrastructure, communications, and decision
4 | making process have stabilized in a manner consistent with other successful ASF projects.
5 | While incubation status is not necessarily a reflection of the completeness or stability
6 | of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
7 |
8 | Some of the incubating project's releases may not be fully compliant with ASF policy. For
9 | example, releases may have incomplete or un-reviewed licensing conditions. What follows is
10 | a list of known issues the project is currently aware of (note that this list, by definition,
11 | is likely to be incomplete):
12 |
13 | * Releases may have incomplete licensing conditions.
14 |
15 | If you are planning to incorporate this work into your product/project, please be aware that
16 | you will need to conduct a thorough licensing review to determine the overall implications of
17 | including this work. For the current status of this project through the Apache Incubator
18 | visit: https://incubator.apache.org/projects/nlpcraft.html
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Apache NLPCraft (Incubating)
2 | Copyright (C) 2021-2024 The Apache Software Foundation
3 |
4 | This product includes software developed at
5 | The Apache Software Foundation (http://www.apache.org/).
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 | [](https://raw.githubusercontent.com/apache/opennlp/master/LICENSE)
22 | [](https://github.com/apache/incubator-nlpcraft/actions)
23 | [](https://nlpcraft.apache.org/docs.html)
24 |
25 | ## What is Apache NLPCraft?
26 | [Apache NLPCraft](https://nlpcraft.apache.org/) is an open source library for adding a natural language interface
27 | for modern applications. It enables people to interact with your products using voice
28 | or text. Make sure to use stable branch **master-0.9.1**:
29 |
30 | * [Instructions](https://nlpcraft.apache.org/download.html) for download, Maven/Grape/Gradle/SBT, build and installation
31 | * Read [documentation](https://nlpcraft.apache.org/docs.html), latest [Scaladoc](https://nlpcraft.apache.org/apis/latest/index.html)
32 | * View & run [examples](https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples)
33 | * File a bug or improvement in [JIRA](https://issues.apache.org/jira/projects/NLPCRAFT)
34 | * Post a question at [Stack Overflow](https://stackoverflow.com/questions/ask) using nlpcraft
tag
35 | * Join project developers on [dev@nlpcraft.apache.org](mailto:dev-subscribe@nlpcraft.apache.org)
36 |
37 | ## Copyright
38 | Copyright (C) 2023 Apache Software Foundation
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/assembly.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
21 | dir
22 |
23 |
24 | dir
25 |
26 |
27 | false
28 |
29 |
30 |
31 | ${project.build.directory}
32 |
33 |
34 | apache-${project.name}-${project.version}-all-deps.jar
35 |
36 |
37 |
38 | ${project.build.directory}/apidocs
39 | javadoc
40 |
41 | **/*.*
42 |
43 |
44 |
45 | ${project.basedir}/src/main/resources
46 |
47 |
48 | *.conf
49 | *.xml
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/bindist/NOTICE:
--------------------------------------------------------------------------------
1 | Apache NLPCraft
2 | Copyright (C) 2021 The Apache Software Foundation
3 |
4 | This product includes software developed at
5 | The Apache Software Foundation (http://www.apache.org/).
6 |
7 |
--------------------------------------------------------------------------------
/nlpcraft-examples/calculator/README.md:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 | [](https://raw.githubusercontent.com/apache/opennlp/master/LICENSE)
22 | [](https://github.com/apache/incubator-nlpcraft/actions)
23 | [](https://nlpcraft.apache.org/docs.html)
24 |
25 | ### Calculator Example
26 | This example data model represents simple calculator. It supports '+', '-', '*' and '/' operations for two integer arguments.
27 | Note that first argument can be omitted and last operation result will be used instead.
28 |
29 | ### Documentation
30 | See [Getting Started](https://nlpcraft.apache.org/docs.html) guide for more instructions on how to run these examples.
31 |
32 | For any questions, feedback or suggestions:
33 |
34 | * View & run other [examples](https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples)
35 | * Read [documentation](https://nlpcraft.apache.org/docs.html), latest [Scaladoc](https://nlpcraft.apache.org/apis/latest/index.html)
36 | * [Download](https://nlpcraft.apache.org/download.html) & [Installation](https://nlpcraft.apache.org/installation.html)
37 | * File a bug or improvement in [JIRA](https://issues.apache.org/jira/projects/NLPCRAFT)
38 | * Post a question at [Stack Overflow](https://stackoverflow.com/questions/ask) using nlpcraft
tag
39 | * Access [GitHub](https://github.com/apache/incubator-nlpcraft) mirror repository.
40 | * Join project developers on [dev@nlpcraft.apache.org](mailto:dev-subscribe@nlpcraft.apache.org)
41 |
42 | ### Copyright
43 | Copyright (C) 2023 Apache Software Foundation
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/nlpcraft-examples/calculator/src/test/scala/org/apache/nlpcraft/examples/time/CalculatorModelSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.time
19 |
20 | import org.apache.nlpcraft.*
21 | import org.scalatest.funsuite.AnyFunSuite
22 |
23 | import scala.util.Using
24 |
25 | /**
26 | * Model validation.
27 | */
28 | class CalculatorModelSpec extends AnyFunSuite:
29 | test("test") {
30 | Using.resource(new NCModelClient(new CalculatorModel())) { client =>
31 | def check(txt: String, v: Int): Unit = require(v == client.ask(txt, "userId").getBody)
32 |
33 | check("2 + 2", 4)
34 | check("3 * 4", 12)
35 | check("/ two", 6)
36 | check("+ twenty two", 28)
37 | check("7 + 2", 9)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-fr/src/main/resources/lightswitch_model_fr.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | macros:
19 | "" : "{allumer|laisser|mettre}"
20 | "" : "{éteindre|couper|tuer|arrêter|éliminer|baisser|no}"
21 | "" : "{entière|pleine|tout|total|_}"
22 | "" : "{là-haut|à l'étage|en bas|{1er|premier|2ème|deuxième|3ème|troisième|4ème|quatrième|5ème|cinquième|dernier|haut|rez-de-chaussée|en bas} étage|_}"
23 | "" : "{chambre|salle|pièce|placard|mansardé|loft|mezzanine|rangement {chambre|salle|pièce|_}}"
24 | "" : "{tout|_} {cela|lumière|éclairage|illumination|lampe}"
25 |
26 | elements:
27 | - type: "ls:loc"
28 | description: "Location of lights."
29 | synonyms:
30 | - " {cuisine|bibliothèque|placard|garage|bureau|salle de jeux|{salle à manger|buanderie|jeu} }"
31 | - " {maître|gamin|bébé|enfant|hôte|client|_} {coucher|bains|toilette|rangement} {|_}"
32 | - " {maison|foyer|bâtiment|{1er|premier} étage|chaussée|{2ème|deuxième} étage}"
33 |
34 | - type: "ls:on"
35 | groups:
36 | - "act"
37 | description: "Light switch ON action."
38 | synonyms:
39 | - "{|_} "
40 | - "{|_} "
41 |
42 | - type: "ls:off"
43 | groups:
44 | - "act"
45 | description: "Light switch OFF action."
46 | synonyms:
47 | - " "
48 | - " "
49 |
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCFrSemanticEntityParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch.nlp.entity.parser
19 |
20 | import opennlp.tools.stemmer.snowball.SnowballStemmer
21 | import org.apache.nlpcraft.examples.lightswitch.nlp.token.parser.NCFrTokenParser
22 | import org.apache.nlpcraft.*
23 | import org.apache.nlpcraft.nlp.stemmer.NCStemmer
24 | import org.apache.nlpcraft.nlp.parsers.*
25 |
26 | /**
27 | * Extension of [[NCSemanticEntityParser]] for FR language.
28 | *
29 | * @param mdlRes Relative path, absolute path, classpath resource or URL to YAML or JSON semantic model definition.
30 | */
31 | class NCFrSemanticEntityParser(mdlRes: String) extends NCSemanticEntityParser(
32 | new NCStemmer:
33 | private val stemmer = new SnowballStemmer(SnowballStemmer.ALGORITHM.FRENCH)
34 | override def stem(word: String): String = stemmer.synchronized { stemmer.stem(word.toLowerCase).toString }
35 | ,
36 | new NCFrTokenParser(),
37 | mdlRes
38 | )
39 |
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/token/enricher/NCFrStopWordsTokenEnricher.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch.nlp.token.enricher
19 |
20 | import org.apache.lucene.analysis.fr.FrenchAnalyzer
21 | import org.apache.nlpcraft.*
22 |
23 | /**
24 | * FR language stop words [[NCTokenEnricher]] implementation based on [[https://lucene.apache.org/ Apache Lucene Library]].
25 | *
26 | * More information about stopwords can be found at [[https://en.wikipedia.org/wiki/Stop_word]]
27 | */
28 | class NCFrStopWordsTokenEnricher extends NCTokenEnricher:
29 | private final val stops = FrenchAnalyzer.getDefaultStopSet
30 |
31 | private def getPos(t: NCToken): String = t.get("pos").getOrElse(throw new NCException("POS not found in token."))
32 | private def getLemma(t: NCToken): String = t.get("lemma").getOrElse(throw new NCException("Lemma not found in token."))
33 |
34 | /** @inheritdoc */
35 | override def enrich(req: NCRequest, cfg: NCModelConfig, toks: List[NCToken]): Unit =
36 | for (t <- toks)
37 | val lemma = getLemma(t)
38 | lazy val pos = getPos(t)
39 |
40 | t.put(
41 | "stopword",
42 | lemma.length == 1 && !Character.isLetter(lemma.head) && !Character.isDigit(lemma.head) ||
43 | stops.contains(lemma.toLowerCase) ||
44 | pos.startsWith("I") ||
45 | pos.startsWith("O") ||
46 | pos.startsWith("P") ||
47 | pos.startsWith("D")
48 | )
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/token/parser/NCFrTokenParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch.nlp.token.parser
19 |
20 | import org.apache.nlpcraft.*
21 | import org.languagetool.tokenizers.fr.FrenchWordTokenizer
22 | import scala.jdk.CollectionConverters.*
23 |
24 | /**
25 | * [[https://languagetool.org/ Language Tool]] based FR language [[NCTokenParser entity parser]].
26 | */
27 | class NCFrTokenParser extends NCTokenParser:
28 | private val tokenizer = new FrenchWordTokenizer
29 |
30 | /** @inheritdoc */
31 | override def tokenize(text: String): List[NCToken] =
32 | val toks = collection.mutable.ArrayBuffer.empty[NCToken]
33 | var sumLen = 0
34 |
35 | for ((word, idx) <- tokenizer.tokenize(text).asScala.zipWithIndex)
36 | val start = sumLen
37 | val end = sumLen + word.length
38 |
39 | if word.strip.nonEmpty then
40 | toks += new NCPropertyMapAdapter with NCToken:
41 | override def getText: String = word
42 | override def getIndex: Int = idx
43 | override def getStartCharIndex: Int = start
44 | override def getEndCharIndex: Int = end
45 |
46 | sumLen = end
47 |
48 | toks.toList
49 |
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-ru/src/main/resources/lightswitch_model_ru.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | macros:
19 | "" : "{включить|включать|врубить|врубать|запустить|запускать|зажигать|зажечь}"
20 | "" : "{погасить|загасить|гасить|выключить|выключать|вырубить|вырубать|отключить|отключать|убрать|убирать|приглушить|приглушать|стоп}"
21 | "" : "{весь|все|всё|повсюду|вокруг|полностью|везде|_}"
22 | "" : "{это|лампа|бра|люстра|светильник|лампочка|лампа|освещение|свет|электричество|электрика|_}"
23 |
24 | elements:
25 | - type: "ls:loc"
26 | description: "Location of lights."
27 | synonyms:
28 | - " {здание|помещение|дом|кухня|детская|кабинет|гостиная|спальня|ванная|туалет|{большая|обеденная|ванная|детская|туалетная} комната}"
29 |
30 | - type: "ls:on"
31 | groups:
32 | - "act"
33 | description: "Light switch ON action."
34 | synonyms:
35 | - " "
36 | - " "
37 |
38 | - type: "ls:off"
39 | groups:
40 | - "act"
41 | description: "Light switch OFF action."
42 | synonyms:
43 | - " "
44 | - " "
45 | - "без "
46 |
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCRuSemanticEntityParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch.nlp.entity.parser
19 |
20 | import opennlp.tools.stemmer.snowball.SnowballStemmer
21 | import org.apache.nlpcraft.examples.lightswitch.nlp.token.parser.NCRuTokenParser
22 | import org.apache.nlpcraft.nlp.parsers.*
23 | import org.apache.nlpcraft.*
24 | import org.apache.nlpcraft.nlp.stemmer.NCStemmer
25 |
26 | /**
27 | * Extension of [[NCSemanticEntityParser]] for RU language.
28 | *
29 | * @param mdlRes Relative path, absolute path, classpath resource or URL to YAML or JSON semantic model definition.
30 | */
31 | class NCRuSemanticEntityParser(mdlRes: String) extends NCSemanticEntityParser(
32 | new NCStemmer:
33 | private val stemmer = new SnowballStemmer(SnowballStemmer.ALGORITHM.RUSSIAN)
34 | override def stem(word: String): String = stemmer.synchronized { stemmer.stem(word.toLowerCase).toString }
35 | ,
36 | new NCRuTokenParser(),
37 | mdlRes
38 | )
39 |
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/token/enricher/NCRuStopWordsTokenEnricher.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch.nlp.token.enricher
19 |
20 | import org.apache.lucene.analysis.ru.RussianAnalyzer
21 | import org.apache.nlpcraft.*
22 |
23 | /**
24 | * RU language stop words [[NCTokenEnricher]] implementation based on [[https://lucene.apache.org/ Apache Lucene Library]].
25 | *
26 | * More information about stopwords can be found at [[https://en.wikipedia.org/wiki/Stop_word]]
27 | */
28 | class NCRuStopWordsTokenEnricher extends NCTokenEnricher:
29 | private final val stops = RussianAnalyzer.getDefaultStopSet
30 |
31 | private def getPos(t: NCToken): String = t.get("pos").getOrElse(throw new NCException("POS not found in token."))
32 | private def getLemma(t: NCToken): String = t.get("lemma").getOrElse(throw new NCException("Lemma not found in token."))
33 |
34 | /** @inheritdoc */
35 | override def enrich(req: NCRequest, cfg: NCModelConfig, toks: List[NCToken]): Unit =
36 | for (t <- toks)
37 | val lemma = getLemma(t)
38 | lazy val pos = getPos(t)
39 |
40 | t.put(
41 | "stopword",
42 | lemma.length == 1 && !Character.isLetter(lemma.head) && !Character.isDigit(lemma.head) ||
43 | stops.contains(lemma.toLowerCase) ||
44 | pos.startsWith("PARTICLE") ||
45 | pos.startsWith("INTERJECTION") ||
46 | pos.startsWith("PREP")
47 | )
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/token/parser/NCRuTokenParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch.nlp.token.parser
19 |
20 | import org.apache.nlpcraft.*
21 | import org.languagetool.tokenizers.WordTokenizer
22 |
23 | import scala.jdk.CollectionConverters.*
24 |
25 | /**
26 | * [[https://languagetool.org/ Language Tool]] based RU language [[NCTokenParser entity parser]].
27 | */
28 | class NCRuTokenParser extends NCTokenParser:
29 | private val tokenizer = new WordTokenizer
30 |
31 | /** @inheritdoc */
32 | override def tokenize(text: String): List[NCToken] =
33 | val toks = collection.mutable.ArrayBuffer.empty[NCToken]
34 | var sumLen = 0
35 |
36 | for ((word, idx) <- tokenizer.tokenize(text).asScala.zipWithIndex)
37 | val start = sumLen
38 | val end = sumLen + word.length
39 |
40 | if word.strip.nonEmpty then
41 | toks += new NCPropertyMapAdapter with NCToken:
42 | override def getText: String = word
43 | override def getIndex: Int = idx
44 | override def getStartCharIndex: Int = start
45 | override def getEndCharIndex: Int = end
46 |
47 | sumLen = end
48 |
49 | toks.toList
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModelSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.lightswitch
19 |
20 | import org.apache.nlpcraft.*
21 | import org.scalatest.funsuite.AnyFunSuite
22 |
23 | import scala.util.Using
24 |
25 | /**
26 | * Model validation.
27 | */
28 | class LightSwitchRuModelSpec extends AnyFunSuite:
29 | test("test") {
30 | Using.resource(new NCModelClient(new LightSwitchRuModel)) { client =>
31 | def check(txt: String): Unit =
32 | require(client.debugAsk(txt, "userId", true).getIntentId == "ls")
33 |
34 | check("Выключи свет по всем доме")
35 | check("Выруби электричество!")
36 | check("Включи свет в детской")
37 | check("Включай повсюду освещение")
38 | check("Включайте лампы в детской комнате")
39 | check("Свет на кухне, пожалуйста, приглуши")
40 | check("Нельзя ли повсюду выключить свет?")
41 | check("Пожалуйста без света")
42 | check("Отключи электричество в ванной")
43 | check("Выключи, пожалуйста, тут всюду свет")
44 | check("Выключай все!")
45 | check("Свет пожалуйста везде включи")
46 | check("Зажги лампу на кухне")
47 | }
48 | }
--------------------------------------------------------------------------------
/nlpcraft-examples/lightswitch/src/main/resources/lightswitch_model.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | macros:
19 | "" : "{turn|switch|dial|let|set|get|put}"
20 | "" : "{shut|kill|stop|eliminate}"
21 | "" : "{entire|full|whole|total|_}"
22 | "" : "{upstairs|downstairs|{1st|first|2nd|second|3rd|third|4th|fourth|5th|fifth|top|ground} floor|_}"
23 | "" : "{room|closet|attic|loft|{store|storage} {room|_}}"
24 | "" : "{all|_} {it|them|light|illumination|lamp|lamplight}"
25 |
26 | elements:
27 | - type: "ls:loc"
28 | description: "Location of lights."
29 | synonyms:
30 | - " {kitchen|library|closet|garage|office|playroom|{dinning|laundry|play} }"
31 | - " {master|kid|children|child|guest|_} {bedroom|bathroom|washroom|storage} {|_}"
32 | - " {house|home|building|{1st|first} floor|{2nd|second} floor}"
33 |
34 | - type: "ls:on"
35 | groups:
36 | - "act"
37 | description: "Light switch ON action."
38 | synonyms:
39 | - " {on|up|_} {on|up|_}"
40 | - " {on|up}"
41 |
42 | - type: "ls:off"
43 | groups:
44 | - "act"
45 | description: "Light switch OFF action."
46 | synonyms:
47 | - " {off|out|down}"
48 | - "{|} {off|out|down} "
49 | - " "
50 | - " "
51 | - "{out|no|off|down} "
52 | - " {out|off|down}"
--------------------------------------------------------------------------------
/nlpcraft-examples/pizzeria/README.md:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 | [](https://raw.githubusercontent.com/apache/opennlp/master/LICENSE)
22 | [](https://github.com/apache/incubator-nlpcraft/actions)
23 | [](https://nlpcraft.apache.org/docs.html)
24 |
25 | ### Pizzeria Example
26 | This example provides a simple implementation for NLI-powered pizzeria order bot.
27 |
28 | ### Documentation
29 | See [Getting Started](https://nlpcraft.apache.org/docs.html) guide for more instructions on how to run these examples.
30 |
31 | For any questions, feedback or suggestions:
32 |
33 | * View & run other [examples](https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples)
34 | * Read [documentation](https://nlpcraft.apache.org/docs.html), latest [Scaladoc](https://nlpcraft.apache.org/apis/latest/index.html)
35 | * [Download](https://nlpcraft.apache.org/download.html) & [Installation](https://nlpcraft.apache.org/installation.html)
36 | * File a bug or improvement in [JIRA](https://issues.apache.org/jira/projects/NLPCRAFT)
37 | * Post a question at [Stack Overflow](https://stackoverflow.com/questions/ask) using nlpcraft
tag
38 | * Access [GitHub](https://github.com/apache/incubator-nlpcraft) mirror repository.
39 | * Join project developers on [dev@nlpcraft.apache.org](mailto:dev-subscribe@nlpcraft.apache.org)
40 |
41 | ### Copyright
42 | Copyright (C) 2023 Apache Software Foundation
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.nlpcraft.examples.pizzeria.components
19 |
20 | import org.apache.nlpcraft.*
21 |
22 | /**
23 | * Custom [[NCEntityValidator]] implementation.
24 | * It throws [[NCRejection]] exception on invalid user request which simplifies main model logic.
25 | */
26 | class PizzeriaOrderValidator extends NCEntityValidator:
27 | /** @inheritdoc */
28 | override def validate(req: NCRequest, cfg: NCModelConfig, ents: List[NCEntity]): Unit =
29 | def count(typ: String): Int = ents.count(_.getType == typ)
30 |
31 | val cntPizza = count("ord:pizza")
32 | val cntDrink = count("ord:drink")
33 | val cntNums = count("stanford:number")
34 | val cntSize = count("ord:pizza:size")
35 |
36 | // Single size - it is order specification request.
37 | if (cntSize != 1 && cntSize > cntPizza) || cntNums > cntPizza + cntDrink then
38 | throw new NCRejection("Invalid pizza request.")
39 |
--------------------------------------------------------------------------------
/nlpcraft-examples/time/README.md:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 | [](https://raw.githubusercontent.com/apache/opennlp/master/LICENSE)
22 | [](https://github.com/apache/incubator-nlpcraft/actions)
23 | [](https://nlpcraft.apache.org/docs.html)
24 |
25 | ### Time Example
26 | This example data model answers the questions about current time, either local to the caller or at some city.
27 | It provides YAML response with time and timezone information and uses YAML model definition.
28 |
29 | ### Documentation
30 | See [Getting Started](https://nlpcraft.apache.org/docs.html) guide for more instructions on how to run these examples.
31 |
32 | For any questions, feedback or suggestions:
33 |
34 | * View & run other [examples](https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples)
35 | * Read [documentation](https://nlpcraft.apache.org/docs.html), latest [Scaladoc](https://nlpcraft.apache.org/apis/latest/index.html)
36 | * [Download](https://nlpcraft.apache.org/download.html) & [Installation](https://nlpcraft.apache.org/installation.html)
37 | * File a bug or improvement in [JIRA](https://issues.apache.org/jira/projects/NLPCRAFT)
38 | * Post a question at [Stack Overflow](https://stackoverflow.com/questions/ask) using nlpcraft
tag
39 | * Access [GitHub](https://github.com/apache/incubator-nlpcraft) mirror repository.
40 | * Join project developers on [dev@nlpcraft.apache.org](mailto:dev-subscribe@nlpcraft.apache.org)
41 |
42 | ### Copyright
43 | Copyright (C) 2023 Apache Software Foundation
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/nlpcraft-examples/time/src/main/resources/time_model.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | macros:
19 | "": "{of|for|per}"
20 | "": "{current|present|now|local}"
21 | "