Instruções

Execute a Markov algorithm

Os conceitos de Markov são utilizados na aprendizagem de máquina, devido à abordagem simples na manipulação de dados. Com um número definido de regras (rules), você pode manipular dados (data) para criar uma saída (output) desejada. Adicionamos em segundo plano: As rules na forma de array aninhado e os data na forma de array também. E os outputs desejados. The rules:
let rules=[
[
"A -> apple","B -> bag","S -> shop","T -> the",
"the shop -> my brother","a never used -> .terminating rule"
],

[
 "A -> apple","B -> bag","S -> .shop","T -> the",
 "the shop -> my brother","a never used -> .terminating rule"
],

[
 "A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag",
 "->.* -> money","W -> WW","S -> .shop","T -> the",
 "the shop -> my brother","a never used -> .terminating rule"
],

[
 "_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX",
 "X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y",
 "1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "
],

[
"A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11",
"B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"
]

];
The data:
let data=[
        "I bought a B of As from T S.",
        "I bought a B of As from T S.",
        "I bought a B of As W my Bgage from T S.",
        "_1111*11111_",
        "000000A000000"
        ];
The outputs:
let outputs=[
    "I bought a bag of apples from my brother.",
    "I bought a bag of apples from T shop.",
    "I bought a bag of apples with my money from T shop.",
    "11111111111111111111",
    "00011H1111000"
    ]
Usando o algoritmo de Markov, altere os dados (data) para que as saídas (outputs) desejadas usem as regras (rules) fornecidas para você.

O que fazer:

Testes:

  • `markov` deve ser uma função.
  • `markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` deve retornar a string `I bought a bag of apples from my brother.`
  • `markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` deve retornar a string `I bought a bag of apples from T shop.`
  • `markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")` deve retornar a string `I bought a bag of apples with my money from T shop.`
  • `markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")` deve retornar a string `11111111111111111111`.
  • `markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")` deve retornar a string `00011H1111000`.

Console