pattern-matching

Scala: How can I match only the first two elements of an arbitrary List

China☆狼群 提交于 2019-12-10 11:49:00
问题 I'm attempting to match a lists first two elements, however, it wont accept lists of arbitrary length. The below code fails. def demoCases() = { def actor1 = new Actor[Employee] {} def actor2 = new Actor[Employee] {} def actor3 = new Actor[Animal] {} var actors = List(actor1, actor2, actor3); println(); actors match { case (_: Employee) :: (_: Employee) :: tail => {println("nice 2 employees to start with ")}; case Nil => {println("no match")} } The exception : Exception in thread "main" scala

Automated website categorization

穿精又带淫゛_ 提交于 2019-12-10 11:42:29
问题 I want to create this engine which will categorize websites based on their meta keyword attribute. Extracting of keyword from the website has been easy as well as connecting with the database. The problem that I am facing is the algorithm how to to match the 'keyword' extracted from the website with the predefined set of strings. Please help me. I am using PHP scripts to implement this. //say I have $pattern as the meta keyword extracted from web page (ignore the syntax – please me) $pattern=

Capture stream of digits which is not followed by certain digits

北城以北 提交于 2019-12-10 11:37:36
问题 I wanted to capture a stream of digits which are not followed by certain digits. For example input = abcdef lookbehind 123456..... asjdnasdh lookbehind 789432 I want to capture 789432 and not 123 using negative lookahead only . I tried (?<=lookbehind )([\d])+(?!456) but it captures 123456 and 789432 . Using (?<=lookbehind )([\d])+?(?!456) captures only 1 and 7 . Grouping is not an option for me as my use case doesn't allow me to do it. Is there any way I can capture 789432 and not 123 using

image matching/detection in iphone using opencv

谁都会走 提交于 2019-12-10 11:29:49
问题 I have 2 images, say bigImage and smallImage. I want to detect whether the smallImage is there anywhere in the bigImage, irrespective of its orientation or transforms(rotations). If its there, it should return true and otherwise return false. I have been going through the template matching (cvMatchTemplate) method in openCV, but haven't reach anywhere since there aren't much difference between the output for a true and a false match. Is my requirement still possible using cvMatchTemplate or

PostgreSQL, find strings differ by n characters

别等时光非礼了梦想. 提交于 2019-12-10 11:27:11
问题 Suppose I have a table like this id data 1 0001 2 1000 3 2010 4 0120 5 0020 6 0002 sql fiddle demo id is primary key, data is fixed length string where characters could be 0, 1, 2. Is there a way to build an index so I could quickly find strings which are differ by n characters from given string? like for string 0001 and n = 1 I want to get row 6. Thanks. 回答1: There is the levenshtein() function, provided by the additional module fuzzystrmatch. It does exactly what you are asking for: SELECT

How to compare two contours of a binary pattern image?

岁酱吖の 提交于 2019-12-10 11:22:13
问题 I'm creating a part scanner in C that pulls all possibilities for scanned parts as images in a directory. My code currently fetches all images from that directory and dumps them into a vector. I then produce groups of contours for all the images. The program then falls into a while loop where it constantly grabs images from a webcam, and generates contours for those as well. I have set up a jig for the part to rest on, so orientation and size are not a concern, however I don't want to have to

Find lines starting with one specific character and ending with another one

梦想与她 提交于 2019-12-10 11:07:04
问题 I need to find a line in a file that starts with an a and the last word in the line ends with an e . How can I do it with a tool like grep ? 回答1: Just say this: grep '^a.*e$' file This means: look for those lines starting ( ^ ) with a , then 0 or more characters and finally and e at the end of the line ( $ ). Test $ cat a hello and thisfinishes with e foo $ grep '^a.*e$' a and thisfinishes with e 回答2: Simple answer : use grep. grep -E "^a.*e$" filename the ^ indicates the beggining of the

pattern matching in Bash [duplicate]

别来无恙 提交于 2019-12-10 10:58:25
问题 This question already has answers here : Syntax with pound and percent sign after shell parameter name (2 answers) Closed 5 months ago . Here is an example to get different parts of a filename bash-3.2$ pathandfile=/tmp/ff.txt bash-3.2$ filename=$(basename $pathandfile) bash-3.2$ echo $filename ff.txt bash-3.2$ echo ${filename##*.} txt bash-3.2$ echo ${filename%.*} ff I was wondering what does ## and % mean in the patterns. How is the patten matching working? Thanks and regards! 回答1: The

F# and negative match

眉间皱痕 提交于 2019-12-10 10:48:35
问题 I have a discriminated type: type Item = | Normal of string * float32 | Special1 of Item | Special2 of Item And I have a function using this type: let rec calcItem (i: Item ) = match i with | Normal(_, p) -> p | Special1(g) | Special2(g) -> (calcItem g) + 1 In my case, the Special_ n types will be defined in the same form. So I am wondering if it is possible to use wildcard pattern to match all these types. The _ match does not work, because it does not accept arguments. 回答1: Similar to this

Finding unknown repeating patterns in a string consisting numbers

冷暖自知 提交于 2019-12-10 10:03:23
问题 I've been struggling with this for a week. I have a string like this: 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1..... What I need to find: 1 1 0 example 2: 1 1 2 0 2 2 1 0 1 1 2 0 2 2 1 0 1 1 2 0 2 2 1 0 1 1 2 0 2 2 1 0 .... What I need to find: 1 1 2 0 2 2 1 0 example 3: 1 1 2 3 1 0 1 1 2 3 1 0 1 1 2 3 1 0 1 1 2 3 1 0 1 1 2 3 1 0... 112310 etc. etc. My code as now: private string tekrarArama(double[] mods) { string part1 = ""; string part2 = ""; string patern = ""; int number1 = mods