Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions prompto-lab-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
<artifactId>fastjson</artifactId>
<version>2.0.57</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.timemachinelab.core.qatree;

import lombok.Data;

@Data
public class CommonQA extends QA {

public CommonQA() {
super(QAType.QA);
}

private String question;

private String answer;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.timemachinelab.core.qatree;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class FormQA extends QA {

private String question;

private Map<String, String> answerMap;

public FormQA() {
super(QAType.FORM);
answerMap = new HashMap<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.timemachinelab.core.qatree;

public abstract class QA {

protected final QAType type;

protected long createTime;

protected long updateTime;

public QA(QAType type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.timemachinelab.core.qatree;

public enum QAType {

QA("QA"),
SELECTION("Selection"),
FORM("Form");

private String name;

QAType(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.timemachinelab.core.qatree;

import lombok.Data;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

public class QaTree {

@Getter
private QaTreeNode root;

private Map<String, QaTreeNode> nodeMap = new HashMap<>();

public QaTree(QaTreeNode root) {
this.root = root;
nodeMap.put(root.getId(), root);
}

public void addNode(String parentId, QaTreeNode node) {
QaTreeNode parent = nodeMap.get(parentId);
if (parent == null) {
return;
}
parent.append(node);
nodeMap.put(node.getId(), node);
}

public QaTreeNode getNodeById(String id) {
return nodeMap.get(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.timemachinelab.core.qatree;

import org.springframework.stereotype.Component;

@Component
public class QaTreeDomain {

public QaTree createTree(String userStartQuestion) {
CommonQA startQA = new CommonQA();
startQA.setQuestion(userStartQuestion);
QaTreeNode startNode = new QaTreeNode(startQA);

return new QaTree(startNode);
}

public QaTree appendNode(QaTree tree, String parentId, QaTreeNode node) {
tree.addNode(parentId, node);
return tree;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.github.timemachinelab.core.qatree;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Data
public class QaTreeNode {

private final String id;

private Map<String, QaTreeNode> children;

private QA qa;

public QaTreeNode(QA qa) {
this.id = UUID.randomUUID().toString();
this.children = new HashMap<>();
this.qa = qa;
}

public void append(QA qa) {
QaTreeNode node = new QaTreeNode(qa);
this.append(node);
}

public void append(QaTreeNode node) {
children.put(node.getId(), node);
}

public QaTreeNode getChild(String id) {
return children.get(id);
}

public boolean hasChild(String id) {
return children.containsKey(id);
}

public void removeChild(String id) {
children.remove(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.timemachinelab.core.qatree;

public class SelectionQA extends QA {

public SelectionQA() {
super(QAType.SELECTION);
}

private String question;

private String[] options;

private Integer selectedOption;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.github.timemachinelab.core.session;

public class Session {
}
Loading