Menu
  • HOME
  • TAGS

Fuzzy matching movie titles without using a loop and extracting equivalent titles by release date

r,matching,string-matching,levenshtein-distance,fuzzy-search

You can merge these data frames z <- merge(df1,df2,by='release_date',suffixes=c('.df1','.df2')) which will give you a cartesian product (i.e. all possible combinations between df1 and df2 for the same release_date, and then calculate the Levenshtein distance by: z$L.dist <- lenvenshteinSim(z$title.df1,z$title.df2) Having z$L.dist, you can filter the desired rows: subset(z,L.dist > 0.85) Update...

Microstrategy documents - matching differen attributes with the same value

attributes,document,matching,value,microstrategy

You can't... or you can try to add the attribute year in the report with year-of-observation and put a filter year = year-of-observation, at this point many things can happen: If the two attributes have no relationship, the lookup table for year will be added to your report query in...

Error using estimateFundamentalMatrix Expected matched_points1 to be one of these types: numeric

matlab,matching,feature-detection,feature-extraction,matlab-cvst

The reason why I got the error massage mentioned above is because the page is for R2014a,but my MATLAB is R2012b,so it is a version problem.We just need to change the code like this: [fMatrix, epipolarInliers, status] = estimateFundamentalMatrix(matchedPoints1.Location, ... matchedPoints2.Location, 'Method', 'RANSAC', 'NumTrials', 10000, 'DistanceThreshold', ... 0.1, 'Confidence', 99.99);...

Java String pattern that takes only specific strings [closed]

java,regex,string,matching

If you want to get these substrings and also trim them, you can use the following regex: String rx = "\\$\\s*([^$]*)\\s*\\$"; Sample code: String str = ")(&^%$ HELLO $#)(&^%..$ this Is the text $KJHGFIUYTRMNBVkjh$I need$gfd987654"; String rx = "\\$\\s*([^$]*)\\s*\\$"; Pattern ptrn = Pattern.compile(rx); Matcher m = ptrn.matcher(str); while (m.find()) {...

data cleaning and matching names in r

r,matching,reshape,reshape2

Try lst <- split(1:ncol(df1),cumsum(grepl('Name', colnames(df1)))) lst2 <- lapply(lst, function(i) {x1 <- na.omit(df1[i]) colnames(x1)[1] <- 'Name' aggregate(.~ Name, x1, mean)}) res <- Reduce(function(...) merge(..., by='Name', all=TRUE), lst2) head(res,2) # Name Taska Bonda Goala Taskb Bondb Goalb Rapport Client #1 Adam Tharker 24.0 24.0 24.0 24 26.0 23.0 NA NA #2 Adam...

Java regex to match absent groups at fixed locations

java,regex,pattern-matching,group,matching

You could use the below regex. ^(?:(\d+)\s+(?:(\S+)\s)?)?([^(]+\([^)]*\))$ DEMO String s = "1234 efg(567)"; Matcher m = Pattern.compile("^(?:(\\d+)\\s+(?:(\\S+)\\s)?)?([^(]+\\([^)]*\\))$").matcher(s); while(m.find()) { if(m.group(1) != null) System.out.println(m.group(1)); if(m.group(2) != null) System.out.println(m.group(2)); if(m.group(3) != null) System.out.println(m.group(3)); } ...

A fast, optimized row matching code

matlab,row,matching

You can use BSXFUN to do it in a vectorized manner: rowsMatched = find(all(bsxfun(@eq, bigMatrix, matchingRow),2)); Notice that it will work for any number of columns, just matchingRow should have the same number of columns as bigMatrix....

How to find maximum number of such pairs of connected edges in a graph that each pair is separated from another pair by at least two edges?

algorithm,graph,matching

The straightforward way to do it would be to create a new graph G' in which you have a vertex for every pair of connected edges in G, and an edge connects two vertices in G' whenever the corresponding edge pairs in G are less than 2 edges apart. You...

How to use regex for matching multiple words in Java

java,regex,matching

You are trying to use alternative lists in a regex, but instead you are using a character class ("[\\baddAction\\b|\\bintentFilter\\b]). With a character class, all characters in it are matched individually, not as a given sequence. You learnt the word boundary, you need to also learn how grouping works. You have...

How does the regex “\” character and grouping “()” character work together?

python,regex,matching,regex-group

Context is important: re.match(r'\(', content) matches a literal parenthesis. re.match(r'\(*', content) matches 0 or more literal parentheses, thus making the parens optional (and allowing more than one of them, but that's clearly a bug). Since the intended behavior isn't "0 or more" but rather "0 or 1", this should probably...

Print all non-matching items in Perl

regex,perl,if-statement,matching

How about using something like Text::Diff instead of building your own? See the comments for the explanation about how you didn't use a capture group to set $1....

C# Find non matching values in DataTables

c#,datatable,matching,relation

Well, you could of course use a little bit of LINQ by turning the data tables into IEnumerables using the AsEnumerable()1 extension method. I am using a few assumptions to illustrate this: "id" is the column with an integer value relating rows in FEData and SSFEData. "id" is the primary...

Read external file match specific string in first column and return respective string of second column in php

php,string,return,matching,vlookup

I suppouse data have not error, so don't do any test $c1 = file('csvurl.txt'); $l = count($c1); for ($i = 0; $i < $l; $i++) { list($name,$url) = explode(',', $c1[$i]); // making array $red['H001'] => 'URL1" $red[trim($name)] = trim($url); } unset($c1); $c = file('tickerMaster.txt'); $l = count($c); for ($i =...

Regex: Matching only the first occurrence?

regex,matching

http://www\.mywebsite\.com/video/.*?_ Try this. Make * non greedy. Better use http://www\.mywebsite\.com/video/[^_]*_ ...

how to compare size of kepoints matching in opencv

c++,opencv,matching,surf

I'm not sure if I quite understand your question. What I understood was that: You will compare images using keypoints You want to compare the size of matched keypoints First u want at least 2 images: Mat image1; //imread stuff here Mat image2; //imread stuff here Then detect keypoints in...

Why doesn't Scala optimize calls to the same Extractor?

scala,matching,extractor

Wouldn't it be reasonable to assume that results from unapply would not change given the same string. Unfortunately, assuming isn't good enough for a (static) compiler. In order for memoizing to be a legal optimization, the compiler has to prove that the expression being memoized is pure and referentially...

awk to match two fields in two files

awk,comparison,matching

Consider: awk -F 'FNR==NR{a[$1];b[$2];next} FNR==1 || ($2 in a && $3 in b)' file1 file2 The option -F expects an argument but no argument is provided intentionally. The result is that awk interprets the entirety of the code as the field separator. That is why that code does not run...

C++ error: no matching constructor for initialization of

c++,constructor,matching

In the line Rectangle box2; // no default constructor, error you are trying to invoke the default constructor of Rectangle. The compiler does not generate such a default constructor anymore, because your Rectangle has a user defined constructor that takes 2 parameters. Therefore, you need to specify the parameters, like...

Creating a counterfactual group for missing values NAs

r,matching,na

It seems I will be able to handle it using Amelia package: http://cran.r-project.org/web/packages/Amelia/vignettes/amelia.pdf#subsection.4.4 http://cran.r-project.org/web/packages/Amelia/Amelia.pdf and true, there is lots of materials on it on Cross Validated, e.g. http://stats.stackexchange.com/questions/95832/missing-values-nas-in-the-test-data-when-using-predict-lm-in-r @nograpes, thank you for all the hints!...

How to find matching rows in Pandas DataFrame with identical values with same/opposite signs in certain columns?

python,pandas,duplicates,dataframes,matching

This idea should work: Self join DF on c,d Apply condition of opposite values... A quick and dirty code ndf = merge(left=df1,right=df1,on=('c','d'),how='inner') out = ndf[(ndf.a_x == (-1)*ndf.a_y) & (ndf.b_x == (-1)*ndf.b_y)] Please let me know if this works...

Look up value, on another Excel sheet

excel,matching,vlookup

Your formula is: =VLOOKUP(A8,Sheet1!A1:B285, 1, FALSE) If you take a look at VLOOKUP description, you will find the following description of the first parameter: The value you want to lookup. The value you want to look up must be in the first column of the range of cells you specify...

Regex to match string with hyphen sign between two numbers

php,regex,matching

Simple: preg_match('/\d+\-\d+/', $string, $match); var_dump($matches); If you want to match all such patterns then use: preg_match_all('/\d+\-\d+/', $string, $matches); var_dump($matches); ...

On signature matching of Standard ML

types,matching,sml,signature

If a structure implements MERGEABLE_QUEUE, it provides a function that takes a pair of queues of arbitrary type (as long as the two queues have the same type as each other) and produces a new queue. In particular, it can take two int queues and produce another int queue (and...

How to collect a continuous set of webpages using python?

python,regex,url,beautifulsoup,matching

You could try this: import urllib2 import shutil urls = [] for i in range(10): urls.append(str('https://www.example.org/users/' + i)) def getUrl(urls): for url in urls: # Only a file_name based on url string file_name = url.replace('https://', '').replace('.', '_').replace('/', '_') response = urllib2.urlopen(url) with open(file_name, 'wb') as out_file: shutil.copyfileobj(response, out_file) getUrl(urls) ...

Regex to match a simple math equation within a string

php,regex,matching

The following samples are all matched. $samples = Array( 'what is 4+3', 'what is 2 plus 7', 'what is 3 * 2', 'what is 3x2', 'what is 4 times 2' ); foreach($samples as $sample) { $sample = preg_replace('/(times)|\*/', 'x', $sample); $sample = str_replace('plus', '+', $sample); preg_match('/what is \d ?[+x] ?\d/',...

for loop plus for in loop

javascript,arrays,matching,javascript-objects

You just need to add an [i] to the second for loop ( for(var key in collection [i]) function where(collection, source) { var arr = []; // What's in a name? for(var i =0; i < collection.length; i++){ for(var key in collection[i]){ if(collection[i][key] === source[key]) { arr.push(collection[i]); } } }...

Match a table in R and return value from row

r,matching

User the faster and more efficient package - data.table: install.packages("data.table") library(data.table) store the list of states that you are looking for in a data table list.states <- as.data.table(state_m) setnames(list.states,1,"STATE_CODE") # give some name to your column eg: STATE_CODE setkey(list.states,STATE_CODE) # merging would be done on STATE_CODE the entire data set...

R Matching based on mutiple columns

r,dataframes,matching

You can use merge, as @MrFlick suggested: df.key <- data.frame( x=c(1,1,2,1,2), y=c(2,1,1,1,3), value=c(10,20,30,20,200)) ## df.add <- data.frame( x=c(1,2,2), y=c(1,1,3), value=c(20,30,300), a=rnorm(3), b=rpois(3,0)) ## > merge( x=df.key, y=df.add) x y value a b 1 1 1 20 0.9246104 0 2 1 1 20 0.9246104 0 3 2 1 30 0.2685016 0...

Match words of permutations of another word using regex [duplicate]

regex,permutation,matching,words

Using lookaheads, with "leap" as an example: \b(?=[a-z]*l)(?=[a-z]*e)(?=[a-z]*a)(?=[a-z]*p)[a-z]+\b Fiddle: http://refiddle.com/12u4 EDIT: I added \b anchors (word boundaries); the leading one is especially important, otherwise "appeal" might be captured three times ("appeal", "ppeal", "peal"). Feel free to use other anchors when appropriate (e.g. ^...$). By the way, this approach is also...

Counting observations under varying conditions in Stata

stata,matching

Try something along the lines of clear set more off *----- example data ----- input /// id str20 date treat match num 1 01feb2000 1 2 2 1 01apr2000 0 . . 1 01jan2002 1 3 1 2 01mar2000 1 3 0 2 01may2000 0 . . 3 01dec2002 1...

PHP: Extracting numbers from a page

php,regex,matching

If I were you I'd just grab the number, and then outside of the regex work out if it fits within your bounds: '(\d+(?:\.\d{1,3})?)\s*/\s*10(?![^<]*/)' Update I realized mine failed when there were more than three decimal positions (grabbed the wrong number), so here's a better one: '(?<![\d.])(\d+(?:\.\d{1,3})?)\s*/\s*10(?![^<]*/)' ...

R: Obtain the matched data set from Matching package - not that easy

r,statistics,matching

This is actually fairly straightforward to reconstruct, if you note that the values in index.treated are repeated M number of times, for those treated cases for which it is possible to find matches within the caliper distance. So, in your case, the the first two elements of index.control are the...

matlab find most similar rows in 2 matrices

matlab,matrix,matching

EDIT 2 : SOLUTION Thanks to the comments provided I managed to come up with a "not elegant" but working solution. B_rem = B; weights_error = [2 4 1]; match = zeros(size(A,1),2); for i = 1 : size(A,1) score = zeros(size(B_rem,1),1); for j =1 : size(B_rem,1) score(j) = sum(abs(A(i,:) -...

How do I find one matching strings in two txt files

sql,file,comparison,substring,matching

Here's how I'd approach it (though using PowerShell rather than SQL): clear pushd c:\myPath\myFolder\ #read in the contents of the files $file1 = get-content("file1.txt") $file2 = get-content("file2.txt") #loop through each row of the whitespace separated file $file1 = $file1 | %{ #for each line, split on whitespace characters, returning the...

Hungarian Algorithm with Mutual Pairs?

c++,algorithm,segmentation-fault,matching,hungarian-algorithm

I think what you want is a version of a maximum matching for a graph that is not bipartite. There is an algorithm described for this at http://en.wikipedia.org/wiki/Blossom_algorithm, and the very last paragraph talks about the weighted case. You want a minimum cost matching, but every maximum matching has the...

extract FASTA sequence using sequence ID [closed]

perl,design-patterns,matching

Edit: New code, I didn't understand your question the first time. This script reads both files, stores all IDs in a hash and then goes through all sequences in the first file. Only those sequences whose IDs are in the second file get written into the output file. Note that...

consistent matched pairs in R

r,for-loop,matching

The problem is that you randomise the order of lalonde, but your input to GenMatch and Match are X and BalanceMat which still have the original order. When you then build your matched.data at the end, you are subsetting using indices which don't tie into lalonde any more. Try again...

print hash keys and values if they are matched

perl,hash,matching,fuzzy-search

A lot of time it is easier to prep your data ahead of time. To make your code simpler later. Here is what I would do create a reverse hash of non-punctuation names to the id. When looping the file I just have to have to compare against my non-punctuation...

Alternation in regular expression NOT working (use of pipe symbol | ) to zero in on value types

regex,tcl,matching

if { [regexp {rise_constraints|fall_constraint} $line] } Doesn't work because there is no rise_constraints in the lines. There is rise_constraint with no s. Also, try to better indent your code next time....

How to assign identical unique IDs to matching observations between two dataframes in r?

r,matching,uniqueidentifier

An easy way to approach this is to make a hash: library(dplyr) library(digest) df1 %>% rowwise() %>% do( data.frame(., id=digest( paste(.$a1,.$b1,.$c1), algo="md5"), stringsAsFactors=FALSE)) %>% ungroup() df2 %>% rowwise() %>% do( data.frame(., id=digest( paste(.$a2,.$b2,.$c2), algo="md5"), stringsAsFactors=FALSE)) %>% ungroup() which would produce the following for df1: a1 b1 c1 id 1 1...

php preg_match_all conditional pattern

php,regex,matching,pcre

I would use @Casimir's answer for this purpose.. If you are looking for a regex.. use the below pattern: <script[^>]*id="(?!pagespeed\b)[^"]+".*<\/script> See DEMO...

How to set values based on a list in Pandas (python)

python,list,pandas,dataframes,matching

Your question still doesn't seem to have enough information to find the real problem. This quick example shows that your attempt can work just fine: import pandas as pd df = pd.DataFrame({'x': [4, 5, 6], 'month': [1, 2, 3]}) some_list = [2, 3] df[df['month'].isin(some_list)] = 99 df Out[13]: month x...

Real-time data matching algorithm

algorithm,real-time,matching

Actually, there are some algorithms from computational biology and genetics that might be suited for fast numbers matching, and also in a field of sequence pattern mining. Check "A FAST Pattern Matching Algorithm" by S. S. Sheik, Sumit K. Aggarwal Anindya Poddar N. Balakrishnan,‡ and K. Sekar Also, it appears...

Exact matching and GenMatch in R

r,matching

I should start by saying that I have never used those packages and functions before, my answer is purely based on playing with your code and the functions documentation. It seems that there is a poorly documented, unwarned, precedence of Weight.matrix over exact in the Match() function. There's a hint...

Inconsistent match function, if I run twice works (R)

r,match,matching

From help(match): "match returns a vector of the positions of (first) matches of its first argument in its second." So it looks at each element in names(current_qty) and returns the position of it in trade_order. So for example it sees "ivvb11" in the second position on trade_order. Then this gets...

Maximum weighted pairing algorithm for complete graph

algorithm,graph-algorithm,matching,scilab

I do not know Scilab I am afraid, but if you are willing to use Python it is very easy as the Networkx library provides support for this function: import networkx as nx import networkx.algorithms.matching as matching def C(i,j): return i*j n=40 G=nx.Graph() for i in range(n): for j in...

Scala match class exactly (not extends)

scala,match,equals,matching

There's a reason the auto-generated equals method doesn't do what you're suggesting. The canEqual convention is a common and well-documented one, because it allows for handling a broader set of common use cases. You don't always want to exclude all sub classes when implementing an equals method, only ones that...

Rails: Advanced sql query

sql,ruby-on-rails,ruby,ruby-on-rails-4,matching

Finding related jobs according to some number of criteria, and weighting the related jobs according to the "closeness of match" certainly sounds like it is a task for the Job class. I'd create a method (perhaps 'get_related_weighted_jobs') in the Job class. Inside that method, use the Job instance's attributes to...

File Handling and making directories to match in bash

bash,shell,sorting,matching,file-handling

#!/bin/bash # If there are no files match File_*.*.txt # replace File_*.*.txt by empty string shopt -s nullglob for i in File_*.*.txt; do echo "processing file $i" IFS="_." read foo num1 num2 foo <<< "$i" printf -v dir1 "Dir_%03d" "$num1" printf -v dir2 "Dir_%03d" "$num2" mkdir -pv "$dir1" "$dir2" cp...

Get the key for a value in my array

php,arrays,matching,username

This question is the continuation of your previous question. Based on that knowledge here is the answer to your question: function getAgentForRejectedUser($rejectedUser, $arrayListeAgence) { foreach ($arrayListeAgence as $agent => $users) { foreach ($users as $user) { $data = explode(' ', $user); if ($data[0] == $rejectedUser) { return $agent; } }...

Can PCL's Registration align a synthetic cloud with a generated one?

registration,matching,point-cloud-library,point-clouds

This is also closely related to object recognition, which in the world of 3D model-based perception is closely tied to pose estimation. One issue that frequently pops up in object recognition is what scales at which to ignore features; calculating features at a larger scale is a way to get...

Find string matching id using JQuery

jquery,string,find,matching

This will work: var full_id = $("input[id ^='test-id-']"); // get the full ID var res = full_id[0].id.split("-"); // split it on "-" var yourId = res[2]; // last part is your ID alert (yourId); // shout it out ...

Implementation of Absolute Differences Stereo Matching Algorithm

matlab,matching,vision,correspondence

This is most probably an imshow issue. The function imshow excepts the image to be in the range [0, 255] if it is a uint8, or [0.0, 1.0] if floating point. Try: imshow(min_cost, []); Note, the empty array for the second argument. This tells Matlab to figure out the scaling....

Matlab SURF points to pixel coordinates

matlab,image-processing,matching,surf,matlab-cvst

To understand it further I tried the following code in this link. % Extract SURF features I = imread('cameraman.tif'); points = detectSURFFeatures(I); [features, valid_points] = extractFeatures(I, points); % Visualize 10 strongest SURF features, including their % scales and orientation which were determined during the % descriptor extraction process. imshow(I); hold...

Find matching elements of two dataframes and assign new value

r,data.frame,matching

You could use left_join from dplyr: > design # ss clusters ICC items CondNum #1 300 10 0.05 10 1 #2 300 10 0.05 20 2 #3 300 10 0.05 50 3 #4 300 10 0.05 70 4 #5 300 10 0.10 10 5 > condition # ss clusters ICC...

MySQL matching row values sets

mysql,matching

I find a similar problem here and based on that i come up with this solution. For the first part of your problem to select how many time same five player were on the ice when the goal is scored your query could look like this: SELECT GROUP_CONCAT(t1.fk_gf_id) AS MinOfGoal,...

Python: efficient way to match 2 different length arrays and find index in larger array

python,arrays,performance,numpy,matching

Since bigx is always evenly spaced, it's quite straightforward to just directly compute the indices: start = bigx[0] step = bigx[1] - bigx[0] indices = ((x - start)/step).round().astype(int) Linear time, no searching necessary....

sed to extract pattern between a substring and first occurance of numeric in a string

sed,matching,substrings

There are quite a few ways to extract the data. The simplest form would be grep. GNU grep: You can grab the required data using GNU grep with PCRE option -P: $ cat file xxx_component1-1.0-2-2acd314.xc-linux-x86-64-Release-devel.r xxx_component2-3.0-1-fg3sdhd.xc-linux-x86-64-Release-devel.r xxx_component3-1.0-2-3gsjcgd.xc-linux-x86-64-Release-devel.r xxx_component4-0.0-2-2acd314.xc-linux-x86-64-Release-devel.r $ grep -oP '(?<=_)[^-]*' file component1 component2 component3 component4 Here we use...

Exception in matchingJsonPath with wiremock

json,matching,wiremock

Looks like a dependency problem. Do you have jsonpath included via some other dependency? If this is the case you might want to try including the standalone version with all dependencies excluded as described here: http://wiremock.org/getting-started.html...

When to use Rabin-Karp or KMP algorithms?

string,algorithm,matching,knuth-morris-pratt,rabin-karp

When you want to search for multiple patterns tipically the correct choice is to use Aho-Corasick which is somewhat a generalization of KMP. Now in your case you are only searching for 3 patterns so it may be the case that KMP is not that much slower(at most three times),...

Draw nearest value from sorted data frame into unsorted data frame

r,matching,cumulative-frequency

findInterval() is perfect for this: set.seed(1); cumFreqDist <- data.frame(Time=c(0,4,6,8,12,16,18,20,24,100), cumfreq=c(0.0000000,0.9009009,1.8018018,7.5075075,23.4234234,39.6396396,53.4534535,58.2582583,75.3753754,100.0000000) ); testData <- data.frame(x=runif(10000)*100); testData$Time <- cumFreqDist$Time[findInterval(testData$x,cumFreqDist$cumfreq)]; head(testData,20); ## x Time ## 1 26.550866 12 ## 2 37.212390 12 ## 3 57.285336 18 ## 4 90.820779 24 ## 5 20.168193 8 ## 6 89.838968 24 ## 7 94.467527 24 ##...

How to get pixel coordinates from Feature Matching

python,opencv,image-processing,matching,feature-detection

matches returns a list of structures where each structure contains several fields... among them are two important fields: queryIdx - The index of the feature into kp1 that matches trainIdx - The index of the feature into kp2 that matches You'd use these to index into kp1 and kp2 and...

jQuery clone list items matching two data attributes

jquery,clone,matching,custom-data-attribute

You may try this (Example): var c = 'usa', t = '1940'; $("li[data-c='" + c + "'][data-t='" + t + "']").clone().appendTo(".someClass" ); Elements that matches both data attribute will be cloned and appended....

Adding up score in matching game java script

javascript,css,function,matching

You pass the (numeric, 0 based) index of the answer to the function select based on the button you clicked. You compare this to the ans property, which has the value 'A' or 'B' for the first questions. 0, obviously, is not equal to 'A'. So change ans to a...

Color Gradient Algorithm in Lab color space

java,algorithm,colors,gradient,matching

To generate a gradient between two color values, you can just linearly interpolate between them. This will basically work in any color space, although if the transformation between two color spaces is not linear, the gradient obtained by linearly interpolating in one space will not be linear in the other....