Commit e17815dd authored by Seyed Reza  Sajjadinasab's avatar Seyed Reza Sajjadinasab
Browse files

fixSLF4Warning

parent 29e90a8e
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ import StateMachine.*;

public class DBinterface {
    public void checkTokenInDatabase(String sentence, DirectedGraph<State> graph){
        StateMachine<State> SM = new StateMachine<>();
        StateMachine SM = new StateMachine();
        sentence = sentence.replaceAll("\\p{Punct}", " $0");
        String[] tokens = sentence.split("\\s+");
        String url = "jdbc:sqlite:./SQLite/mydatabase.db";
@@ -41,12 +41,8 @@ public class DBinterface {

            // Check if the sequence of actions follows the state machine

            boolean isFollowed = SM.isStateMachineFollowed(graph, actions, initialState);
            if (isFollowed) {
                System.out.println("Sequence of actions follows the state machine.");
            } else {
                System.out.println("Sequence of actions does not follow the state machine.");
            }
            int confidence = SM.isStateMachineFollowed(graph, actions, initialState);
            System.out.print("The confidence score is: "+ confidence + "\n");
        } catch (SQLException e) {
            e.printStackTrace();
        }
+13 −14
Original line number Diff line number Diff line
@@ -7,18 +7,17 @@ public class Main {
        DirectedGraph<State> graph = new DirectedGraph<>();
        
        
        // Build the state machine graph
        graph.addNode(State.START);
        graph.addNode(State.PRONOUN);
        graph.addNode(State.VERB);
        graph.addNode(State.ADJECTIVE);
        graph.addNode(State.ADVERB);
        graph.addNode(State.ARTICLE);
        graph.addNode(State.CONJ);
        graph.addNode(State.COMMA);
        graph.addNode(State.NOUN);
        graph.addNode(State.DOT);
        State cur = State.first();
        for(int i=0; i<State.values().length; i++){
            graph.addNode(cur);
            cur = cur.next();
        }

        cur = State.first();
        for(int i=1; i<State.values().length; i++){
            cur = cur.next();
            graph.addEdge(State.first(), cur);
        }

        graph.addEdge(State.START,     State.PRONOUN);
        graph.addEdge(State.PRONOUN,   State.VERB);
@@ -40,7 +39,7 @@ public class Main {

        
        // Sentence to tokenize
        String sentence = "it is a very good book, and it is very small.";
        String sentence = "it a very good book it good";
        // Tokenize the sentence
        DBinterface dbInterface = new DBinterface();

@@ -50,4 +49,4 @@ public class Main {
}

//javac -d bin Main.java **/*.java
//java -cp bin:SQLite/sqlite-jdbc-3.45.2.0.jar:SQLite/slf4j-api-1.7.36.jar Main
 No newline at end of file
//java -cp bin:SQLite/sqlite-jdbc-3.45.2.0.jar:SQLite/slf4j-api-1.7.36.jar:SQLite/slf4j-jdk14-1.7.36.jar Main 
 No newline at end of file
+8.24 KiB

File added.

No diff preview for this file type.

+10 −0
Original line number Diff line number Diff line
@@ -27,4 +27,14 @@ public enum State {
            }
            return NAN;
        }

        public State next() {
            State[] colors = State.values();
            return colors[(this.ordinal()+1)%colors.length];
          }
        

        static public State first() {
            return State.values()[0];
        }
}
+9 −7
Original line number Diff line number Diff line
@@ -3,16 +3,18 @@ package StateMachine;
import java.util.List;

import DirectedGraph.DirectedGraph;
public class StateMachine<NodeClass>{
    public boolean isStateMachineFollowed(DirectedGraph<NodeClass> graph, List<NodeClass> actions, NodeClass initialState) {
        NodeClass currentState = initialState;
        for (NodeClass action : actions) {
            List<NodeClass> transitions = graph.getAdjacentNodes(currentState);
public class StateMachine{
    public int isStateMachineFollowed(DirectedGraph<State> graph, List<State> actions, State initialState) {
        int confidence = 0;
        State currentState = initialState;
        for (State action : actions) {
            List<State> transitions = graph.getAdjacentNodes(currentState);
            if (!transitions.contains(action)) {
                return false; // Action not allowed in current state
                currentState = State.START;
                confidence += 10; // Action not allowed in current state
            }
            currentState = action; // Transition to the next state
        }
        return true;
        return confidence;
    }
}
 No newline at end of file
Loading