问题
Is there any possibility to decode Morse code to text if the code is in following format(without any white spaces):
-.-..--.....-...--..----.
Normally it looks like that,
- .-. .- -. ... .-.. .- - .. --- -.
t r a n s l a t i o n
but is it possible, to get the same text from Morse code without white spaces?
回答1:
This is possible to do, but it becomes problematic as you end up generating a large number of possible options.
First start with a Morse mapping:
private Dictionary<string, string> map = new Dictionary<string, string>()
{
{ ".-", "a" },
{ "-...", "b" },
{ "-.-.", "c" },
{ "-..", "d" },
{ ".", "e" },
{ "..-.", "f" },
{ "--.", "g" },
{ "....", "h" },
{ "..", "i" },
{ ".---", "j" },
{ "-.-", "k" },
{ ".-..", "l" },
{ "--", "m" },
{ "-.", "n" },
{ "---", "o" },
{ ".--.", "p" },
{ "--.-", "q" },
{ ".-.", "r" },
{ "...", "s" },
{ "-", "t" },
{ "..-", "u" },
{ "...-", "v" },
{ ".--", "x" },
{ "-..-", "y" },
{ "-.--", "z" },
{ "--..", " " },
};
Then this function can produce the possible decodings:
public IEnumerable<string> DecodeMorse(string morse)
{
var letters =
map
.Where(kvp => morse.StartsWith(kvp.Key))
.Select(kvp => new
{
letter = kvp.Value,
remainder = morse.Substring(kvp.Key.Length)
})
.ToArray();
if (letters.Any())
{
var query =
from l in letters
from x in DecodeMorse(l.remainder)
select l.letter + x;
return query.ToArray();
}
else
{
return new [] { "" };
}
}
Now, given a shorter version of your input morse, "-.-..--....", I got 741 possible strings. Here's the cut down version:
cabe
cadee
cadi
…
tranie
trans
trateeee
…
trxii
trxse
It includes "trans" so it seems to be working.
Running on the full string produces 5,914,901 possible with "translation" as one of the possibilities.
Incidentally, there were 4,519 possible strings that simply started with "trans". How humans could do this on the fly is amazing!
回答2:
What you are proposing isn't really possible.
You will not be able to tell where one letter ends and the next begins. How will you be able to tell the difference between letters? Will the first letter be -
, -.
, or -.-
?
回答3:
There is no doubt in my mind that given a sufficiently advanced algorithm, and sufficient context around each letter, that it is possible to get a high level of accuracy. However the problem approaches AGI-level difficulty the greater accuracy that you require, because this is one of the skills (fast pattern matching in language) that humans are particularly good at and machines are nowhere near as good at (yet). The reason for that, is that broader context that makes pattern matching possible for humans includes not just possible words, but semantics and the overall meaning of the story, and mapping that to model of the world that makes sense. This is something that is extremely difficult to program a computer to do. Also the human brain is massively parallel.
Also, it is fairly trivial to prove that a general perfect solution is impossible (perfect accurate translation for every possible input string). For example, consider simply the short string ".--", that could mean "at" or "em", both valid English words.
回答4:
You need to know where the characters start and end. Take, for instance:
...---...
If you divide it one way, you get:
... --- ... = SOS
However, if you divide it differently, you may get:
. .. - -- . .. = EITMEI
So, is it possible? Technically, yes, it's possible. However, you would have a huge number of possible solutions that would take a long time to identify and translate. With a database of commonly seen words, you might be able to make this a bit smarter, but it would still be a best-effort.
来源:https://stackoverflow.com/questions/22418182/decode-morse-without-white-spaces-to-text