Quantcast
Channel: Active questions tagged wolfram-alpha-queries - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 58

A femme is a wife is a Frau

$
0
0

As can be seen from

LanguageData["Properties"] // Multicolumn

enter image description here

Mathematica's translation capabilities seem to be very limited. It can translate month names, colors and numbers, but, apparently, not arbitrary words.

Grid[ LanguageData[  {   Entity["Language", "English"],   Entity["Language", "German"],   Entity["Language", "Spanish"]   }, "NumeralWords"], Frame -> All, Alignment -> Left]

enter image description here

To translate arbitrary words one probably has to use WolframAlpha:

word = "femme";trans = WolframAlpha[word <> " from french to german", "PodCells"]

enter image description here

This doesn' t look too bad, but how do we get "femme", "Frau" and "Ehefrau" as a List of Strings ? Executing

trans // FullForm

we see a complex structure of RowBoxes - instructions. To eliminate the unwanted elements I have written

res = DeleteCases[   Cases[trans, _String, Infinity],"\")\"" | "\"(\"" | "\" \"" | "\"  |  \"" | "Columns" | "\"French\"" | "\"from\"" | "\"general\"" |"\"German\"" | "Output" | "\"person\"" | "Rows" | "RowDefault" | "RowsIndexed" | "Times" |"\"to\"" | "\"translate\"" | "\[NoBreak]" | "Verdana",   Infinity] // DeleteDuplicates

{"\"femme\"", "\"Frau\"", "\"Ehefrau\"", "\"wife\"", "\"woman\""}

To eliminate the backslash characters:

str = ToCharacterCode[res] /. (34) -> Sequence[] // FromCharacterCode

{"femme", "Frau", "Ehefrau", "wife", "woman"}

Since we want to translate from french to german we finally eliminate the englisch words :

Flatten @ Map[Intersection[DictionaryLookup[{#, All}], str] &,{"French", "German"}]

{"femme", "Ehefrau", "Frau"}

Voilà, a femme is a wife is a Frau - but at what expense !

How can I simplify this code (especially the RowBoxes - destruction) ?

Are there alternate ways to translate simple words from one language to another ?


Viewing all articles
Browse latest Browse all 58

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>