Tag Info

Hot answers tagged

11

Try this: Replace[list, {x_, "can", _} :> {x, "can", "This"}, 1] OR list /. {x_, "can", _} :> {x, "can", "This"} {{"yes", "can", "This"}, {"yes", "can", "This"}, {"yes", "not", "fgh"}, {"yes", "can", "This"}, {"yes", "not", "h"}} As per your comment, use Alternatives (|): Replace[list, {x_, y : "can" | "cann", _} :> {x, y, "This"}, 1]


8

The following may be useful as starters: WolframAlpha["femme from french to german",{{"Translation:TranslationData", 1}, "ComputableData"}] (* {" Frau | Ehefrau", " Frau"} *)


8

Indeed, StringCases does not have an operator form in 10.0.1. The documentation and usage message appear to be in error. StringCases does not appear on the list TypeSystem`$OperatorForms -- although that is by no means conclusive as discussed here. I would argue that it should have an operator form, in symmetry with Cases. In any event, there is a bug ...


5

You can use Internal`StringToDouble: Map[Internal`StringToDouble, {{"425060", "0.214235E+07", "0.48", "0.01", "0.39", "0.49", "0.01", "0.38", "1.64", "-1.65", "-2.13", "518"}, {"6650479", "0.934695E+06", "0.48", "0.39", "0.43", "0.49", "0.39", "0.44", "2.20", "-0.72", "0.51", "226"}, {"1248079", "0.153025E+07", "0.04", "0.07", "0.30", ...


3

Here is a rough attempt at implementing what you describe, primarily using StringSplit. Fold[ Flatten @ StringSplit[##] &, StringReplace[text[[1]], "," | "*" :> ""], { StartOfLine ~~ Whitespace ... ~~ DigitCharacter ~~ Except["\n"] .. ~~ "\n", WordBoundary ~~ ("." | ";" | ":") ~~ Whitespace, "\n" } ] // StringTrim {"Since all activities ...


3

This seems to be a normal way to extract the data:- xml = XMLObject["Document"][{XMLObject["Declaration"] ["Version" -> "1.0", "Encoding" -> "UTF-8", "Standalone" -> "yes"]}, XMLElement["file", {"name" -> "filename.xml"}, {XMLElement["tekst", {"write" -> "test1"}, {XMLElement["relation", {"type" -> "co-synonyms", ...


3

ClearAll[dL]; dL = Function[{str}, With[{s = Last@str}, Thread[s -> DictionaryLookup[Alternatives @@ (StringExpression @@ StringSplit[StringInsert[s, ".", #], "." -> LetterCharacter] & /@ Range[1 + StringLength@s])]]], Listable]; edges = DeleteDuplicates@Flatten@Rest@NestList[dL, {"a" ...


3

I post this (if I understand the question from title and text: single letter addition anywhere in string) to illustrate how unwieldy the graph gets just 3 levels deep. Here just starting with "a". fun[x_] := With[{c = Characters[x]}, Thread[x -> Select[ DictionaryLookup[ StringExpression @@ Riffle[c, ___, {1, 2 Length@c + 1, 2}]], ...


3

I am the original poser of this question which is not a homework question as belisarius could have realized by noting my identity. (Frankly, belisarius' statement that it was related to a homework problem he assigned did nothing to help me and others interested, and in fact apparently dissuaded others from addressing this problem. I grant that all would ...


2

There is an internal function that might be of use here. pol = m*u*x^4*y + n*v*x^2*y^3; GroebnerBasis`DistributedTermsList[pol, {u, v, x, y}][[1]] (* Out[176]= {{{1, 0, 4, 1}, m}, {{0, 1, 2, 3}, n}} *)


2

In this case what you want is simple/regular enough that you can define the XMLElement etc. as functions that return what you want inside a Block: Block[{XMLObject, XMLElement}, XMLObject["Document"] = #2 &; XMLElement["tekst", {"write" -> t_}, data_] := {t, Sequence @@ data}; XMLElement["lu", attr_, data_] := "id" /. attr; XMLElement[tag_, ...


2

The following can be used to extract the identifiers used in a given test case, which matches the "write" attribute of an individual XMLElement. Note that the attribute names "write" and "id" are hard-coded, which is not ideal. GetIdentifiers[data_, test_String] := Module[{elem, attr}, (*find test case*) elem = Cases[data, XMLElement[___, {___, ...


2

Just as a complement to @MikeHoneychurch, a pure RegularExpression solution: tweet2 = "Designing interventions for food security and prevention of malnutrition in Bangladesh #sensemaker http://t.co/wulTxX3vVK and some other stuff" StringReplace[tweet2, RegularExpression["http://t.co/.+?\\b"] :> ""] or, to remove additional spaces: ...


2

If the link is always at the end you could do something like: StringReplace[tweet, "http://t.co/" ~~ __ ~~ EndOfString :> ""] if not then try tweet2 = "Designing interventions for food security and prevention of malnutrition in Bangladesh #sensemaker http://t.co/wulTxX3vVK and some other stuff" StringReplace[tweet2,Shortest["http://t.co/" ~~ __ ~~ ...


2

I propose pol = m*u*x^4*y + n*v*x^2*y^3 Defer@*Times @@@ CoefficientRules[pol /. {u|v -> 1, x -> x y}, {x, y}] // Total (* {4, 5} m + {2, 5} n *) Use Composition[Defer, Times] instead of Defer@*Times if you have version 9 or earlier. A more general definition: vars = {x, y}; ignore = {u, v}; Defer@Times@## &[#2, Accumulate@#[[;; ...


1

Try this: StringSplit[ StringReplace[First@text, Shortest[(x : DigitCharacter) ~~ __ ~~ "\n"] | ")" | "(" | "*" -> ""], "." | ";" | "," | ":"] which gives the following somewhat imperfect output: {" Since all activities lectures", " seminars", " laboratories at \ Humber are conducted in English", " it is essential that all students ...


1

Thanks to kguler's marvelous solution I was able to write a little translation program. Due to a certain unreliability of WolframAlpha results it is far from being perfect, but fun to play with. ToWords[res_] := DeleteDuplicates @ StringTrim @ Flatten @ Map[StringSplit[#, "|"] &, res] Translator[word_, from_, to_] := ToWords @ WolframAlpha[word ...


1

Assuming that the example XML shown is representative, then we can exploit the fact the write and id attribute names are unambiguous within tekst elements: Cases[test , XMLElement["tekst", a_, c_] :> Sequence["write" /. a, Cases[c, ("id" -> i_) :> i, -1]] , -1 ] (* { "test1", {"AA-504771", "BB-59362", "CC-59362"}, "test2", {"AA-20210", ...


1

You could use a mix of Transpose and Map to create the structure: Transpose[{ITEM, Transpose /@ Transpose[{SUBITEM, SUBSUBITEM}]}] {{Item one, {{subitem a, {subsubitem 1, subsubitem 2, subsubitem 3, subsubitem 4}}, {subitem b, {}}}}, {Item two, {{subitem a, {subsubitem 1}}}}} Then add your title text to the ITEM and SUBITEM elements, and join ...



Only top voted, non community-wiki answers of a minimum length are eligible