Click here to Skip to main content
15,887,585 members
Home / Discussions / Java
   

Java

 
AnswerRe: java Pin
Jameshandra2-Nov-15 19:42
Jameshandra2-Nov-15 19:42 
QuestionNewbie to forum, and JAVA - Question Pin
Member 120400297-Oct-15 4:39
Member 120400297-Oct-15 4:39 
AnswerRe: Newbie to forum, and JAVA - Question Pin
Richard MacCutchan7-Oct-15 5:07
mveRichard MacCutchan7-Oct-15 5:07 
QuestionJava beginner question Pin
mjs585-Oct-15 15:44
mjs585-Oct-15 15:44 
AnswerRe: Java beginner question Pin
Richard MacCutchan5-Oct-15 20:51
mveRichard MacCutchan5-Oct-15 20:51 
Questionwhat is java version of window desktop elements Pin
neodeaths5-Oct-15 0:37
neodeaths5-Oct-15 0:37 
AnswerRe: what is java version of window desktop elements Pin
Richard MacCutchan5-Oct-15 0:45
mveRichard MacCutchan5-Oct-15 0:45 
QuestionHow can I implement Markov's algorithm with variables and markers? Pin
Riccardo Bove4-Oct-15 10:31
Riccardo Bove4-Oct-15 10:31 
Hi! I've been trying to implement Markov's algorithm, but I've only had partial success. The algorithm is fairly simple and can be found here.

However, my project has an added difficulty, I have to use rules that include markers and variables.

A variable represents any letter in the alphabet and a marker is simply a character that is used as a reference to move the variables around (It doesn't have a real value).

This example duplicates every character in a string:

Alphabet: {a,b,c}
Markers: {M}
Variables: {x}

Rule 1: Mx -> xxM
Rule 2: xM -> x
Rule 3: x -> Mx

input: abc

abc //We apply rule 3
Mabc //We apply rule 1
aaMbc //We apply rule 1
aabbMc //We apply rule 1
aabbccM //We apply rule 2
aabbcc

This is my recursive function that implements a markov algorithm that only works with string inputs for example: Rule 1: "apple" -> "orange", Input: "apple".

Java
public static String markov(String input, LinkedList<Rule> rules) {
    for (Rule rule : rules) {
        if (!input.equals(input.replace(rule.getFrom(), rule.getTo()))) {
            if (rule.isTerminating()) {
                input = input.replaceFirst(Pattern.quote(rule.getFrom()), rule.getTo());
                System.out.println(input);
                return input;
            } else {
                input = input.replaceFirst(Pattern.quote(rule.getFrom()), rule.getTo());
                System.out.println(input);
                return markov(input, rules);
            }
        }
    }
    return input;
}


I can't figure out how to implement variables and markers into this logic so perhaps someone can educate me on the best way to implement this logic? any advice is welcome.

Thank You!
GitHub
Questionjava Pin
Member 120298853-Oct-15 0:39
Member 120298853-Oct-15 0:39 
AnswerRe: java Pin
Richard MacCutchan3-Oct-15 1:22
mveRichard MacCutchan3-Oct-15 1:22 
QuestionJava problem beginner Pin
Member 120276961-Oct-15 23:33
Member 120276961-Oct-15 23:33 
AnswerRe: Java problem beginner Pin
Richard MacCutchan2-Oct-15 0:17
mveRichard MacCutchan2-Oct-15 0:17 
GeneralRe: Java problem beginner Pin
Member 120276962-Oct-15 1:46
Member 120276962-Oct-15 1:46 
GeneralRe: Java problem beginner Pin
Richard MacCutchan2-Oct-15 1:53
mveRichard MacCutchan2-Oct-15 1:53 
QuestionStoring private data in the cloud via hash functions? Pin
Keld Ølykke30-Sep-15 10:30
Keld Ølykke30-Sep-15 10:30 
QuestionJava Graphics class Pin
Member 1200394822-Sep-15 8:04
Member 1200394822-Sep-15 8:04 
AnswerRe: Java Graphics class Pin
Richard MacCutchan22-Sep-15 21:11
mveRichard MacCutchan22-Sep-15 21:11 
AnswerRe: Java Graphics class Pin
Anji Reddy26-Sep-15 6:20
Anji Reddy26-Sep-15 6:20 
QuestionUninstalling the Sun java application server problems Pin
Stephen Holdorf22-Sep-15 2:01
Stephen Holdorf22-Sep-15 2:01 
AnswerRe: Uninstalling the Sun java application server problems Pin
Richard MacCutchan22-Sep-15 21:09
mveRichard MacCutchan22-Sep-15 21:09 
QuestionWhile upgrading the axis2, i got the following java.lang.RuntimeException: Undefined 'Security policy namespace cannot be null.' resource property Pin
RohitSonawat17-Sep-15 1:26
RohitSonawat17-Sep-15 1:26 
SuggestionRe: While upgrading the axis2, i got the following java.lang.RuntimeException: Undefined 'Security policy namespace cannot be null.' resource property Pin
Richard MacCutchan17-Sep-15 1:54
mveRichard MacCutchan17-Sep-15 1:54 
Questiontranscript management using java Pin
Member 1197700411-Sep-15 4:45
Member 1197700411-Sep-15 4:45 
AnswerRe: transcript management using java Pin
Richard MacCutchan11-Sep-15 5:31
mveRichard MacCutchan11-Sep-15 5:31 
Questionbooks examples of precedures stored for sqlserver Pin
DAGOBERTO PAVEZ CASELLA8-Sep-15 6:37
professionalDAGOBERTO PAVEZ CASELLA8-Sep-15 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.