This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ZhaoDingfan/basic-structure
Basic structure built up
- Loading branch information
Showing
23 changed files
with
238 additions
and
42 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
core/src/main/java/org/mifos/chatbot/core/ChatService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.mifos.chatbot.core; | ||
|
||
import org.mifos.chatbot.core.model.Message; | ||
|
||
/** | ||
* User input | ||
*/ | ||
|
||
public interface ChatService { | ||
void connect(ChatCallBack chatCallBack); | ||
void disconnect(); | ||
void send(Message msg); | ||
|
||
interface ChatCallBack { | ||
void onMessage(Message msg); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
core/src/main/java/org/mifos/chatbot/core/MifosService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.mifos.chatbot.core; | ||
|
||
import org.mifos.chatbot.core.model.MifosRequest; | ||
import org.mifos.chatbot.core.model.MifosResponse; | ||
|
||
/** | ||
* Connection with Mifos backend | ||
*/ | ||
|
||
public interface MifosService { | ||
MifosResponse process(MifosRequest request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.mifos.chatbot.core; | ||
|
||
import org.mifos.chatbot.core.model.Intent; | ||
|
||
/** | ||
* This interface will handle the OpenNLP engine currently | ||
* If there are other NLP engines, simply add more interfaces for additional NLP engines | ||
*/ | ||
public interface NLPService { | ||
Intent recognize(String text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.mifos.chatbot.core.model; | ||
|
||
public class Intent { | ||
// the data holder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.mifos.chatbot.core.model; | ||
|
||
public class Message { | ||
private String from; | ||
private String to; | ||
private String text; | ||
} |
4 changes: 4 additions & 0 deletions
4
core/src/main/java/org/mifos/chatbot/core/model/MifosRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.mifos.chatbot.core.model; | ||
|
||
public class MifosRequest { | ||
} |
4 changes: 4 additions & 0 deletions
4
core/src/main/java/org/mifos/chatbot/core/model/MifosResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.mifos.chatbot.core.model; | ||
|
||
public class MifosResponse { | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon May 21 22:10:44 SGT 2018 | ||
#Thu May 24 23:47:34 SGT 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
description = "Mifos Chatbot Client" | ||
// https://mvnrepository.com/artifact/org.apache.opennlp/opennlp-tools | ||
|
||
buildscript { | ||
ext { | ||
springBootVersion = '2.0.2.RELEASE' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") | ||
} | ||
} | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'org.springframework.boot' | ||
apply plugin: "io.spring.dependency-management" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom 'io.spring.platform:platform-bom:1.1.1.RELEASE' | ||
} | ||
} | ||
|
||
dependencies { | ||
compile group: 'org.apache.opennlp', name: 'opennlp-tools', version: '1.5.2-incubating' | ||
|
||
compile('org.springframework.boot:spring-boot-starter') | ||
testCompile('org.springframework.boot:spring-boot-starter-test') | ||
testCompile group: 'junit', name: 'junit', version: '4.4' | ||
compile 'org.apache.opennlp:opennlp-tools:1.8.4' | ||
compile 'org.springframework:spring-core' | ||
compile project(':core') | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
nlp/src/main/java/org/mifos/chatbot/nlp/OpenNLPService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.mifos.chatbot.nlp; | ||
|
||
import org.mifos.chatbot.core.NLPService; | ||
import org.mifos.chatbot.core.model.Intent; | ||
|
||
public class OpenNLPService implements NLPService { | ||
|
||
@Override | ||
public Intent recognize(String text) { | ||
return null; | ||
} | ||
|
||
// Refer to OpenNLP framework as much as I want | ||
|
||
// OpenNLP may has to be trained by myself to be financial focused | ||
// May start with 10 keywords first, let framework understand different sentence structure. | ||
|
||
|
||
|
||
// create training set and training model by myself instead of using pre-trained model | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
nlp/src/main/java/org/mifos/chatbot/nlp/SentenceDetector.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
nlp/src/test/java/org/mifos/chatbot/nlp/OpenNLPServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.mifos.chatbot.nlp; | ||
|
||
import org.junit.Test; | ||
import org.mifos.chatbot.core.NLPService; | ||
import org.mifos.chatbot.core.model.Intent; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class OpenNLPServiceTest { | ||
@Autowired | ||
private NLPService nlpService; | ||
|
||
@Test | ||
public void recognizeTest() { | ||
Intent result = nlpService.recognize(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.mifos.chatbot.nlp; | ||
|
||
import opennlp.tools.cmdline.PerformanceMonitor; | ||
import opennlp.tools.cmdline.postag.POSModelLoader; | ||
import opennlp.tools.postag.POSModel; | ||
import opennlp.tools.postag.POSSample; | ||
import opennlp.tools.postag.POSTaggerME; | ||
import opennlp.tools.sentdetect.SentenceDetectorME; | ||
import opennlp.tools.sentdetect.SentenceModel; | ||
import opennlp.tools.tokenize.Tokenizer; | ||
import opennlp.tools.tokenize.TokenizerME; | ||
import opennlp.tools.tokenize.TokenizerModel; | ||
import opennlp.tools.tokenize.WhitespaceTokenizer; | ||
import opennlp.tools.util.InputStreamFactory; | ||
import opennlp.tools.util.ObjectStream; | ||
import opennlp.tools.util.PlainTextByLineStream; | ||
import org.junit.Test; | ||
|
||
import java.io.*; | ||
|
||
public class OpenNLPTest { | ||
@Test | ||
public void detectSentenceTest() throws Exception { | ||
String sentence = ""; | ||
InputStream is = new FileInputStream("en-sent.bin"); | ||
SentenceModel model = new SentenceModel(is); | ||
SentenceDetectorME sdetector = new SentenceDetectorME(model); | ||
|
||
String sentences[] = sdetector.sentDetect(sentence); | ||
is.close(); | ||
} | ||
|
||
@Test | ||
public void tokenize() throws Exception { | ||
InputStream is = new FileInputStream("en-token.bin"); | ||
|
||
TokenizerModel model = new TokenizerModel(is); | ||
|
||
Tokenizer tokenizer = new TokenizerME(model); | ||
|
||
String tokens[] = tokenizer.tokenize("Hi. How are you? This is Mike."); | ||
|
||
for (String a : tokens) | ||
System.out.println(a); | ||
|
||
is.close(); | ||
} | ||
|
||
@Test | ||
public void posTag() throws Exception { | ||
POSModel model = new POSModelLoader() | ||
.load(new File("en-pos-maxent.bin")); | ||
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); | ||
POSTaggerME tagger = new POSTaggerME(model); | ||
|
||
String input = "Hi. How are you? This is Mike."; | ||
ObjectStream<String> lineStream = new PlainTextByLineStream(new InputStreamFactory() { | ||
@Override | ||
public InputStream createInputStream() throws IOException { | ||
return new ByteArrayInputStream(input.getBytes()); | ||
} | ||
}, "UTF-8"); | ||
|
||
perfMon.start(); | ||
String line; | ||
while ((line = lineStream.read()) != null) { | ||
|
||
String whitespaceTokenizerLine[] = WhitespaceTokenizer.INSTANCE | ||
.tokenize(line); | ||
String[] tags = tagger.tag(whitespaceTokenizerLine); | ||
|
||
POSSample sample = new POSSample(whitespaceTokenizerLine, tags); | ||
System.out.println(sample.toString()); | ||
|
||
perfMon.incrementCounter(); | ||
} | ||
perfMon.stopAndPrintFinalResult(); | ||
} | ||
} | ||
|
||
|
22 changes: 22 additions & 0 deletions
22
server/src/main/java/org/mifos/chatbot/server/ChatWithUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.mifos.chatbot.server; | ||
|
||
import org.mifos.chatbot.core.ChatService; | ||
import org.mifos.chatbot.core.model.Message; | ||
|
||
public class ChatWithUserService implements ChatService { | ||
|
||
@Override | ||
public void connect(ChatCallBack chatCallBack) { | ||
|
||
} | ||
|
||
@Override | ||
public void disconnect() { | ||
|
||
} | ||
|
||
@Override | ||
public void send(Message msg) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server.port=10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ include ":core" | |
include ":nlp" | ||
include ":protocol" | ||
include ":server" | ||
|