pattern-matching

detect if a combination of string objects from an array matches against any commands

倖福魔咒の 提交于 2019-12-13 06:02:37
问题 Please be patient and read my current scenario. My question is below. My application takes in speech input and is successfully able to group words that match together to form either one word or a group of words - called phrases; be it a name , an action , a pet , or a time frame. I have a master list of the phrases that are allowed and are stored in their respective arrays. So I have the following arrays validNamesArray , validActionsArray , validPetsArray , and a validTimeFramesArray . A new

Scala expected exception snippet

耗尽温柔 提交于 2019-12-13 05:36:57
问题 I'm trying to simulate the expected exception behavior of common testing frameworks (e.g. JUnit or TestNG). Here's what I could come up with so far (working): trait ExpectAsserts { self : { def fail (message : String) def success (message : String) } => def expect[T](exceptionClass : Class[T])(test : => Unit) { try { test fail("exception not thrown") } catch { case expected : T => success("got exception " + expected) case other : Exception => fail("expected "+ exceptionClass + " but " + other

Pattern matching with integer in haskell gives wrong result

此生再无相见时 提交于 2019-12-13 05:26:40
问题 I noticed that trying to perform pattern matching in haskell with the arguments doesn't quite always work. Here's an example: test :: Integer -> Integer -> String test num1 num2 = case num1 of num2 -> "foo" otherwise -> "bar" When I load this in the interpreter, it warns me of overlapping pattern matches. Further more, test a b for any two integers a and b returns "foo" , regardless of whether they're equal or not. It appears that the num2 in the pattern match is not the same as the one in

In Python, count unique key/value pairs in a dictionary

最后都变了- 提交于 2019-12-13 04:36:58
问题 I have a dictionary that is made with a list of values. Some of these values are also keys or values in other key/value pairs in the dictionary. I would simply like to count how many of these unique pairs there are in the dictionary. Ex. dict = {'dog':['milo','otis','laurel','hardy'],'cat':['bob','joe'],'milo':['otis','laurel','hardy','dog'],'bob':['cat','joe'],'hardy':['dog']} I need to count the number of key/value pairs that do not have share a key/value with another in the dict. For

pattern matching an array, not their elements per se

自古美人都是妖i 提交于 2019-12-13 03:27:15
问题 I'm looking for a way of pattern matching the "geometry" of an array, the order in which the elements appear, not the contents of each element directly. Let me outline what I mean by some examples. Given the target array: array('T_STRING','T_VARIABLE','ASSIGN','T_STRING','LPAREN','T_VARIABLE','COMMA','T_VARIABLE','RPAREN'); //as a matter of fact, these would be the tokens for the PHP code "foo $var = Foo($arg1,$arg2)' Then the following "pattern" would match, returning the 0-based indexes of

Using vb.net and RegEx to find string inside nested string

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 03:08:59
问题 Using VB.NET, Is there a way to do this RegEx call in 1 step... instead of 2-3? I'm trying to find the word "bingo", or whatever is between the START and END words, but then also inside the inner FISH and CAKES words. My final results should be just "bingo". Dim s1 As String = "START (random string) FISH bingo CAKES (random string) END" Dim m As Match m = RegEx.Match(s1, "START\w*END") If (m.Success) Then Dim s2 As String = m.Groups(0).ToString() m = RegEx.Match(s2, "FISH\w*CAKES") if(m

Deleting records with number repeating more than 5

▼魔方 西西 提交于 2019-12-13 02:38:04
问题 I have data in a table of length 9 where data is like 999999969 000000089 666666689 I want to delete only those data in which any number from 1-9 is repeating more than 5 times. 回答1: This can be much simpler with a regular expression using a back reference. DELETE FROM tbl WHERE col ~ '([1-9])\1{5}'; That's all. Explain ([1-9]) ... a character class with digits from 1 to 9, parenthesized for the following back reference. \1 ... back reference to first (and only in this case) parenthesized

How to match all characters except right crotchet (close square bracket) with SQL's PatIndex?

跟風遠走 提交于 2019-12-13 02:34:58
问题 In the below code example, all results should return 7. Those with aliases beginning X however, do not. select --where matches patindex('%-%' ,'111111-11') dash --not a special character, so works without escaping ,patindex('%[%' ,'111111[11') xLeftCrotchet --special character [ not escaped; works ,patindex('%[[]%','111111[11') leftCrotchetEscaped --special character [ escaped to [[]; doesn't work ,patindex('%]%' ,'111111]11') rightCrotchet --special character ] not escaped; doesn't work

Select words with vowels in List<T>

不想你离开。 提交于 2019-12-13 02:33:14
问题 I use StreamReader Class to read from txt file and load it into List, now i want to select on words with vowels and store them into new List so i can use StreamWriter to write only selected words into new txt file 回答1: To select words from a given list of words (that you retrieve however) you can select the ones that only contain vowels using Linq: string vowels = "aeiou"; List<string> words = new List<string>(); //words populated var vowelWords = words.Where( word => word.All( c => vowels

Extract pattern from column

不想你离开。 提交于 2019-12-13 01:17:27
问题 I am struggling with a huge Excel sheet (with 200K rows), where I need to extract from a certain column (B) list of all email addresses present in the string. What I want to achieve: Extract the email from string convert (at) to @ and (dot) to . Save name and email in separate columns Example of column B: Shubhomoy Biswas <biswas_shubhomoy777(at)yahoo(dot)com> Puneet Arora <ar.puneetarora(at)gmail(dot)com> Anand Upadhyay <001.anand(at)gmail(dot)com> Rajat Gupta <rajatgupta0889(at)gmail(dot