New answers tagged

0

I'm not quite sure what you're doing but just to provide a different approach that you might adapt: testcase = <|"fruit" -> {"apple", "pear", "banana"}, "color" -> {"green", "red", "yellow", "orange"}|>; pat = cat : # ~~ "(" ~~ elem : Alternatives @@ #2 ~~ ")" & @@@ Normal[testcase]; StringSplit[{"color(orange)", "fruit(orange)"}, ...


1

Use may use either QuantityForm or StringReplace. startTime = Now; endTime = DatePlus[startTime, {4, "Seconds"}]; timeElapsed = DateDifference[startTime, endTime, {"Hour", "Minute", "Second"}]; Then ToString@QuantityForm[timeElapsed, "Abbreviation"] 0 h 0 min 4. s or StringReplace[{" hours" -> "h", " minutes" -> "m", " seconds" -> "s"}]@...


2

Keep testcase as Association (it was a Dataset) testcase = <|"fruit" -> {"apple", "pear", "banana"}, "color" -> {"green", "red", "yellow", "orange"}|>; Have a cup of coffee, clear your brain and think of the following simple approach: StringSplit[{"color(orange)", "fruit(orange)"}, PatternSequence[category : categoryExistPattern, "(", ...


0

Should we wish to force the output columns appear in an explicitly specified order, then we can use this: columns[ls_][e_] := <| FirstCase[e, n_ # :> # -> n, # -> 0, {0, 1}] & /@ ls |> initDataS[Values, All, columns[{"Train", "Tail", "Loop"}]] This also allows us to select only a subset of the available columns: initDataS[Values, All, ...


0

There are many ways to do this, among others: whitelist = {"Cow and Milk", "Chicken and Egg"} ReadList[StringToStream[ "Cow and Milk and Chicken and Egg and Pig and Sheep"] , Word , RecordLists -> True , RecordSeparators -> whitelist , WordSeparators -> "and" , TokenWords -> whitelist] ...


0

If your file.tsv has data such as: "4d2" 2.3e+02 105.5 "5e1" -1.3e05 235 Then SemanticImport may help: data = SemanticImport["file.tsv",{"String","Number","Number"}, "HeaderLines"-> 0] Set HeaderLines appropriately to reflect the presence of header row(s) in your file.


4

Block[{Missing = (0 &)}, Transpose[Transpose@ initDataS[1, All, Association[# /. Times | Plus -> List /. {a_, b_String} :> b -> a] &]]]


0

How about this? nots = RegularExpression["[^s]"]; DictionaryLookup[{"Catalan", a___ ~~ "s" ~~ b__ /; StringEndsQ[a, nots] && StringStartsQ[b, nots] && StringEndsQ[b, nots]}] where the substring a has a string length of $ \geq 0 $ and not ends with "s", and at the same time the substring b has a length of $ \geq 1 $ without "s" as its two ...


1

Here are a few different approaches. dict = DictionaryLookup[{"Catalan", ___ ~~ "s" ~~ ___}, 140]; DeleteCases[dict, str_ /; StringMatchQ[str, Alternatives[___ ~~ "ss" ~~ ___ , ___ ~~ "s"]]] Select[dict, Not@StringMatchQ[#, Alternatives[___ ~~ "ss" ~~ ___ , ___ ~~ "s"]] &] Select[dict, (StringFreeQ[#, "ss"] && StringFreeQ[#, "s" ~~ ...


2

A Regex attempt: StringCases[#, RegularExpression["[(]nsubj,\s+[(]([^,]+)"] :> "$1"]&/@dep {{He}, {I, he}} StringCases[#, RegularExpression["^[(]([^,]+)"] :> "$1"]&/@dep {{wrote}, {read}}


1

This should work for all of the specified combinations of whitespace/newline date = " Jan 28 , 2020 \n" dateObj = date // StringReplace[" " -> ""] // DateObject[{#, {"Month", "Day", "Year"}}] & DateDifference[dateObj, Today] (* Quantity[21, "Days"] *)


1

StringCases[string, RegularExpression["[0-9]{4},\\s([A-Z]+)"]:> "$1"] {{TEXTDATA, NEXTTEXTDATA}} (In Mathematica, $1 refers to the capturing group (within the parentheses)). string2 = {"text, 1993, TEXTDATA, text, 2007, NEXTTEXTDATA"}; StringCases[string2, RegularExpression["[0-9]{4},\\s+([A-Z]+)"]:> "$1"] {{TEXTDATA, NEXTTEXTDATA}} ...


3

For the moment, it seems to suffice just to understand the selection criterion as to find all the substrings consisting of upper letters. To convey that information, one can use RegularExpression or CharacterRange to construct the string pattern. string = {"text, 1998, TEXTDATA, text, 2007, NEXTTEXTDATA"}; stringpattern1 = RegularExpression["[[:upper:]]+"]; ...


2

string = {"text, 1998, TEXTDATA, text, 2007, NEXTTEXTDATA"}; list = StringSplit[string[[1]], ", "]; filter = RotateRight[StringMatchQ[list, NumberString]]; Pick[list, filter] {"TEXTDATA", "NEXTTEXTDATA"}


4

StringCases[string, DigitCharacter .. ~~ ", " ~~ w : (LetterCharacter ..) :> w] {{"TEXTDATA", "NEXTTEXTDATA"}} or StringCases[string, NumberString ~~ ", " ~~ w : (LetterCharacter ..) :> w] {{"TEXTDATA", "NEXTTEXTDATA"}} or StringCases[string, ", " ~~ w : (LetterCharacter ..) ~~ EndOfString | "," :> w] {{"TEXTDATA", "NEXTTEXTDATA"}}


5

Try these: StringCases[dep, "((nsubj, (" ~~ w : WordCharacter .. ~~ ", " ~~ DigitCharacter .. ~~ "))" :> w] StringCases[dep, "(" ~~ w : WordCharacter .. ~~ ___ :> w] {{"He"}, {"I", "he"}} {{"wrote"}, {"read"}}


5

How about doing this instead of adapting RepaceRepeated: FixedPoint[ StringReplace[{"{}" -> "", "[]" -> "", "()" -> ""}] , "(({{[[]]}})" ] === ""


4

str = TextStructure["I read the book he wrote.", "DependencyStrings"]; {"(read, 2)((nsubj, (I, 1)), (dobj, (book, 4)((det, (the, 3)), (rcmod, (wrote, 6)((nsubj, (he, 5)))))))"} ToExpression @ StringReplace["{" <> str[[1]] <> "}", {")(" -> "}, {", "(" -> "{", ")" -> "}"}] {{read, 2}, {{nsubj, {I, 1}}, {dobj, {book, ...


7

Yes, so first we convert them into quantities: quantities = Interpreter[Restricted["Quantity", "Megabytes"]][st] Now we can eg add them with Total@quantities or sort them with Sort@quantities. In the Interpreter specification, we restrict the type of quantity to one that is compatible with "Megabytes". This is because otherwise, "4.0K" is normally ...


1

Something like this may do it: editLine = "a * Sinc[ b*t + c*u ]"; noEdit = "# COMMENT"; text = {noEdit, noEdit, editLine, editLine, noEdit, editLine}; count = 0; newText = StringReplace[text, { "[" -> "(", "]" -> ")", "t" :> ("m.lammda" <> ToString[++count] <> "[i]*180/np.pi"), "u" :> ("m.phi" <> ToString[count] &...


Top 50 recent answers are included