Search Results

Search found 2490 results on 100 pages for 'matching'.

Page 10/100 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Next line matching the regex in bash

    - by Lin_freak
    I have a file in the format: Port Number IP address Port Number IP address (Not sure how the output will be displayed here but let me tell you they are on separate lines) and so on.... I use the command grep -C 1 'port number' file.txt i.e. I want all IP addresses corresponding to a particular port. Making it simple, I want the next line matching a regular expression. Like if my regular expression matches line 2,4 and 6 then I want lines 3, 5 and 7 to be printed. How to do that?

    Read the article

  • partial string matching - R

    - by DonDyck
    I need to write a query in R to match partial string in column names. I am looking for something similar to LIKE operator in SQL. For e.g, if I know beginning, middle or end part of the string I would write the query in format: LIKE 'beginning%middle%' in SQL and it would return matching strings. In pmatch or grep it seems I can only specify 'beginning' , 'end' and not the order. Is there any similar function in R that I am looking for? For example, say I am looking in the vector: y<- c("I am looking for a dog", "looking for a new dog", "a dog", "I am just looking") Lets say I want to write a query which picks "looking for a new dog" and I know start of the string is "looking" and end of string is "dog". If I do a grep("dog",y) it will return 1,2,3. Is there any way I can specify beginning and end in grep?

    Read the article

  • Regex: markdown-style link matching

    - by The.Anti.9
    I want to parse markdown style links, but I'm having some trouble matching the reference style ones. Like this one: [id]: http://example.com/ "Optional Title Here" My regex gets the id and the url, but not the title. Heres what I have: /\[([a-zA-Z0-9_-]+)\]: (\S+)\s?("".*?"")?/ I go through and add the references to a hashtable. the id as the key and the value is an instance of a class I made called LinkReference that just contains the url and the title. In case the problem is not my regex, and my code adding the matches to the hash table, Heres my code for that too: Regex rx = new Regex(@"\[([a-zA-Z0-9_-]+)\]: (\S+)\s?("".*?"")?"); MatchCollection matches = rx.Matches(InputText); foreach (Match match in matches) { GroupCollection groups = match.Groups; string title = null; try { title = groups[3].Value; } catch (Exception) { // keep title null } LinkReferences.Add(groups[1].Value, new LinkReference(groups[2].Value, title)); }

    Read the article

  • Help matching fields between two classes

    - by Michael
    I'm not too experienced with Java yet, and I'm hoping someone can steer me in the right direction because right now I feel like I'm just beating my head against a wall... The first class is called MeasuredParams, and it's got 40+ numeric fields (height, weight, waistSize, wristSize - some int, but mostly double). The second class is a statistical classifier called Classifier. It's been trained on a subset of the MeasuredParams fields. The names of the fields that the Classifier has been trained on is stored, in order, in an array called reqdFields. What I need to do is load a new array, toClassify, with the values stored in the fields from MeasuredParams that match the field list (including order) found in reqdFields. I can make any changes necessary to the MeasuredParams class, but I'm stuck with Classifier as it is. My brute-force approach was to get rid of the fields in MeasuredParams and use an arrayList instead, and store the field names in an Enum object to act as an index pointer. Then loop through the reqdFields list, one element at a time, and find the matching name in the Enum object to find the correct position in the arrayList. Load the value stored at that positon into toClassify, and then continue on to the next element in reqdFields. I'm not sure how exactly I would search through the Enum object - it would be a lot easier if the field names were stored in a second arrayList. But then the index positions between the two would have to stay matched, and I'm back to using an Enum. I think. I've been running around in circles all afternoon, and I keep thinking there must be an easier way of doing it. I'm just stuck right now and can't see past what I've started. Any help would be GREATLY appreciated. Thanks so much! Michael

    Read the article

  • jQuery hide all table rows which contain a hidden field matching a value

    - by Famous Nerd
    Though I don't doubt this has been answered I cannot find a great match for my question. I have a table for which I'd like to filter rows based on whether or not they contain a hidden field matching a value. I understand that the technique tends to be "show all rows", "filter the set", "show/hide that filtered set" I have the following jquery but I'm aweful with filter and my filtered set seems to always contain no elements. my table is the usual <table> <tr><td>header></td><td>&nbsp;</tr> <tr> <td>a visible cell</td><td><input type='hidden' id='big-asp.net-id' value='what-im-filtering-on' /> </td> </tr> </table> My goal is to be able to match on tr who's descendent contains a hidden input containing either true or false. this is how I've tried the selector (variations of this) and I'm not even testing for the value yet. function OnFilterChanged(e){ //debugger; var checkedVal = $("#filters input[type='radio']:checked").val(); var allRows = $("#match-grid-container .tabular-data tr"); if(checkedVal=="all"){ allRows.show(); } else if(checkedVal=="matched"){ allRows.show(); allRows.filter(function(){$(this).find("input[type='hidden'][id~='IsAutoMatchHiddenField']")}).hide(); } else if(checkedVal=="unmatched"){ } } Am I way off with the filter? is the $(this) required in the filter so that i can do the descendant searching? Thanks kindly

    Read the article

  • Matching Class arrays

    - by frinkz
    I'm writing a routine to invoke methods, found by a name and an array of parameter Class values Matching the Method by getName works, but when trying to match the given Class[] for parameters, and Method.getParameterTypes(), I'm having trouble. I assumed that this would work: Class[] searchParams = new Class[] { float.class, String.class }; Class[] methodParams = m.getParameterTypes(); if(methodParams == searchParams) { m.invoke(this, paramValues); } But apparantly not - m.invoke is never reached. I've checked, and methodParams gives the same classes as searchParams. The code below works, and picks the right method, but it seems like a very dirty way of doing things, I'm sure I'm missing something obvious. Class[] searchParams = new Class[] { float.class, String.class }; Class[] methodParams = m.getParameterTypes(); boolean isMatch = true; for(int i = 0; i < searchParams.length; i++) { if(!searchParams.getClass().equals(methodParams.getClass())) { isMatch = false; } } if(isMatch) { m.invoke(this, paramValues); }

    Read the article

  • PHP: cannot matching string "<br />

    - by Patrick
    hi, I'm having problems with string matching in PHP. I've 2 html elements in my page, I've copy pasted here the content with Firebug <div class="field-item odd"> <div class="field-label-inline-first"> Year:</div> 2009 </div> <div class="field-item odd"> <div class="field-label-inline-first"> Synopsis:</div> &lt;br /&gt; </div> This php line works perfectly (the element with 2009 is detected) <?php if ($items[0]['view'] == '2009') : echo "ok"; ?> However I'm not able to match the string containing element: <?php if ($items[0]['view'] == '<br />') : echo "ok"; ?> //doesn't work <?php if ($items[0]['view'] == '&lt;br /&gt;') : echo "ok"; ?> //again doesn't work any tip ? To give you some context: The strings are produced by CKEditor, an editor I'm using in my Drupal back-end. When I leave empty this editor, the tag is displayed on the string as plain text (because I set "plain text" as formatting option in the back-end) Thanks

    Read the article

  • Determining whether values can potentially match a regular expression, given more input

    - by Andreas Grech
    I am currently writing an application in JavaScript where I'm matching input to regular expressions, but I also need to find a way how to match strings to parts of the regular expressions. For example: var invalid = "x", potentially = "g", valid = "ggg", gReg = /^ggg$/; gReg.test(invalid); //returns false (correct) gReg.test(valid); //returns true (correct) Now I need to find a way to somehow determine that the value of the potentially variable doesn't exactly match the /^ggg$/ expression, BUT with more input, it potentially can! So for example in this case, the potentially variable is g, but if two more g's are appended to it, it will match the regular expression /^ggg$/ But in the case of invalid, it can never match the /^ggg$/ expression, no matter how many characters you append to it. So how can I determine if a string has or doesn't have potential to match a particular regular expression?

    Read the article

  • Regular Expressions: Positive Lookahead and Word Border question

    - by Inf.S
    Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to match the substring "phone" from within them. However, in both case, I want only "phone" to be returned, not "phones" in the first case. In addition to this, I want matches only if the word "phone" is a suffix only, such that: fonephonetics (just an example) is not matched. I assumed that the regex (phone([?=s])?)\b would give me what I need, but it is currently matching "phones" and "phone", but not the "fonephonetics" one. I don't need "phones". I want "phone" for both cases. Any ideas about what is wrong, and what I can do? Thank you in advance!

    Read the article

  • Match returning a string instead of object

    - by Pablo
    This simple regex matching returns a string instead of an object on every browser but the latest firefox... text = "language. Filename: My Old School Yard.avi. File description: File size: 701.54 MB. View on Megavideo. Enter this, here:" name = text.match(/(Filename:)(.*) File /); alert(typeof(name)); as far as i know this the match function is suppose to return an object (Array). Has anyone come across this issue?

    Read the article

  • Scala wont pattern match with java.lang.String and Case Class

    - by Stefan
    Hello fellow Scala Programmers I have been working with Scala for some month now, however I have a problem with some properly basic stuff, I am hoping you will help my out with it. case class PersonClass(name: String, age: Int) object CaseTester { def main(args:Array[String]) { val string = "hej" string match { case e:String => println(string) case PersonClass => println(string) } } } When I am doing like this I get error: pattern type is incompatible with expected type; found : object PersonClass required: java.lang.String case PersonClass = println(string) And if I then change the second line in the pattern matching to the following: case e:PersonClass => println(string) I then get the error: error: scrutinee is incompatible with pattern type; found : PersonClass required: java.lang.String case e:PersonClass = println(string) However if I change the string definition to the following it compiles fine in both cases. val string:AnyRef = "hej"

    Read the article

  • In OpenRasta is it possible to Pattern match multiple key/value pairs?

    - by Scott Littlewood
    Is it possible in OpenRasta to have a Uri pattern that allows for an array of values of the same key to be submitted and mapped to a handler method accepting an array of the query parameters. Example: Return all the contacts named Dave Smith from a collection. HTTP GET /contacts?filterBy=first&filterValue=Dave&filterBy=last&filterValue=Smith With a configuration of: What syntax would be best for the Uri string pattern matching? (Suggestions welcome) ResourceSpace.Has.ResourcesOfType<List<ContactResource>>() .AtUri("/contacts") .And.AtUri("/contacts?filterBy[]={filterBy}[]&filterValue[]={fv}[]") // Option 1 .And.AtUri("/contacts?filterBy={filterBy}[]&fv={fv}[]") // Option 2 Would map to a Handler method of: public object Get(params Filter[] filters) { /* create a Linq Expression based on the filters using dynamic linq query the repository using the Linq */ return Query.All<Contact>().Where(c => c.First == "Dave" && c.Last == "Smith").ToResource() } where Filter is defined by public class Filter { public string FilterBy { get; set; } public string FilterValue { get; set; } }

    Read the article

  • How to perform a literal match with regex using wildcard

    - by kashif4u
    I am trying to perform literal match with regular expression using wildcard. string utterance = "Show me customer id 19"; string pattern 1 = "*tom*"; string patter 2 = "*customer id [0-9]*"; Desired results: if (Regex.IsMatch(utterance, pattern 1 )) { MATCH NOT FOUND } if (Regex.IsMatch(utterance, pattern 2 )) { MATCH FOUND } I have tried looking for literal match solution/syntax in wildcard but having difficulty. Could you also enlighten me with with an example on possible Pattern Matching Strength algorithm i.e. if code match 90 select? Note: I have table with 100000 records to perform literal matches from user utterances. Thanks in advance.

    Read the article

  • Is it possible to match with decomposed sequences in F#?

    - by Ball
    I seem to remember an older version of F# allowing structural decomposition when matching sequences just like lists. Is there a way to use the list syntax while keeping the sequence lazy? I'm hoping to avoid a lot of calls to Seq.head and Seq.skip 1. I'm hoping for something like: let decomposable (xs:seq<'a>) = match xs with | h :: t -> true | _ -> false seq{ 1..100 } |> decomposable But this only handles lists and gives a type error when using sequences. When using List.of_seq, it seems to evaluate all the elements in the sequence, even if it is infinite.

    Read the article

  • Ninject WithConstructorArgument : No matching bindings are available, and the type is not self-bindable

    - by Jean-François Beauchamp
    My understanding of WithConstructorArgument is probably erroneous, because the following is not working: I have a service, lets call it MyService, whose constructor is taking multiple objects, and a string parameter called testEmail. For this string parameter, I added the following Ninject binding: string testEmail = "[email protected]"; kernel.Bind<IMyService>().To<MyService>().WithConstructorArgument("testEmail", testEmail); However, when executing the following line of code, I get an exception: var myService = kernel.Get<MyService>(); Here is the exception I get: Error activating string No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency string into parameter testEmail of constructor of type MyService 1) Request for MyService Suggestions: 1) Ensure that you have defined a binding for string. 2) If the binding was defined in a module, ensure that the module has been loaded into the kernel. 3) Ensure you have not accidentally created more than one kernel. 4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name. 5) If you are using automatic module loading, ensure the search path and filters are correct. What am I doing wrong here? UPDATE: Here is the MyService constructor: [Ninject.Inject] public MyService(IMyRepository myRepository, IMyEventService myEventService, IUnitOfWork unitOfWork, ILoggingService log, IEmailService emailService, IConfigurationManager config, HttpContextBase httpContext, string testEmail) { this.myRepository = myRepository; this.myEventService = myEventService; this.unitOfWork = unitOfWork; this.log = log; this.emailService = emailService; this.config = config; this.httpContext = httpContext; this.testEmail = testEmail; } I have standard bindings for all the constructor parameter types. Only 'string' has no binding, and HttpContextBase has a binding that is a bit different: kernel.Bind<HttpContextBase>().ToMethod(context => new HttpContextWrapper(new HttpContext(new MyHttpRequest("", "", "", null, new StringWriter())))); and MyHttpRequest is defined as follows: public class MyHttpRequest : SimpleWorkerRequest { public string UserHostAddress; public string RawUrl; public MyHttpRequest(string appVirtualDir, string appPhysicalDir, string page, string query, TextWriter output) : base(appVirtualDir, appPhysicalDir, page, query, output) { this.UserHostAddress = "127.0.0.1"; this.RawUrl = null; } }

    Read the article

  • Applying styles to a GridView matching certain criteria

    - by NickK
    Hi everyone. I'm fairly new to ASP.Net so it's probably just me being a bit stupid, but I just can't figure out why this isn't working. Basically, I have a GridView control (GridView1) on a page which is reading from a database. I already have a CSS style applied to the GridView and all I want to do is change the background image applied in the style depending on if a certain cell has data in it or not. The way I'm trying to handle this change is updating the CSS class applied to each row through C#. I have the code below doing this: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = e.Row; string s = row.Cells[7].Text; if (s.Length > 0) { row.CssClass = "newRowBackground"; } else { row.CssClass = "oldRowBackground"; } } In theory, the data from Cell[7] will either be null or be a string (in this case, likely a person's name). The problem is that when the page loads, every row in the GridView has the new style applied to it, whether it's empty or not. However, when I change it to use hard coded examples, it works fine. So for example, the below would work exactly how I want it to: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = e.Row; string s = row.Cells[7].Text; if (s == "Smith") //Matching a name in one of the rows { row.CssClass = "newRowBackground"; } else { row.CssClass = "oldRowBackground"; } } It seems as if the top piece of code is always returning the string with a value greater than 0, but when I check the database the fields are all null (except for my test record of "Smith"). I'm probably doing something very simple that's wrong here, but I can't see what. Like I said, I'm still very new to this. One thing I have tried is changing the argument in the if statement to things like: if (s != null), if (s != "") and if (s == string.empty) all with no luck. Any help is greatly appreciated and don't hesitate to tell me if I'm just being stupid here. :)

    Read the article

  • MSBUILD ClickOnce Error: Deployment and application do not have matching security zones

    - by fande455
    We're trying to publish a ClickOnce application through msbuild. We've got it working fine for an installed version of the windows application. However, when we set install to false so that it just runs the app from the web we get the following error when we try to run the application from the URL: "Deployment and application do not have matching security zones" This works fine in IE. We only get the error message in Chrome and FireFox. Here is a sample of the project file settings. <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <PropertyGroup> <SrcTreeRoot>$(MSBuildProjectDirectory)\..\..\..</SrcTreeRoot> <!--ClickOnceDeployFolder>$(WebOutputDir)\AnalyzerPC</ClickOnceDeployFolder--> <ProjectGuid>{8205E593-F400-41AE-8D6F-DEA290B2DCF9}</ProjectGuid> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ApplicationIcon>Graphics\EDA Icon.ico</ApplicationIcon> <AssemblyName>DASHQueryBuilder</AssemblyName> <OutputType>WinExe</OutputType> <RootNamespace>TetraData.Analyzer</RootNamespace> <FileUpgradeFlags> </FileUpgradeFlags> <OldToolsVersion>2.0</OldToolsVersion> <IsWebBootstrapper>false</IsWebBootstrapper> <ManifestCertificateThumbprint>...</ManifestCertificateThumbprint> <GenerateManifests>true</GenerateManifests> <SignManifests>true</SignManifests> <SignAssembly>true</SignAssembly> <ManifestKeyFile>$(BuildDir)\Certificates\TetraDataCode.pfx</ManifestKeyFile> <ProductVersion>9.0.21022</ProductVersion> <PublishUrl>http://localhost/DASHQueryBuilder/</PublishUrl> <Install>false</Install> <!--InstallFrom>Web</InstallFrom--> <UpdateEnabled>false</UpdateEnabled> <MapFileExtensions>true</MapFileExtensions> <PublisherName>Follett Software Company</PublisherName> <TrustUrlParameters>true</TrustUrlParameters> <ApplicationRevision>0</ApplicationRevision> <UseApplicationTrust>false</UseApplicationTrust> <PublishWizardCompleted>true</PublishWizardCompleted> <BootstrapperEnabled>false</BootstrapperEnabled> </PropertyGroup> <Import Project="$(SrcTreeRoot)\Build\TaskInit.Tasks" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(SrcTreeRoot)\Build\TaskOverrides.Tasks" /> <Import Project="$(MSBuildProjectDirectory)\Analyzer.csproj" /> <PropertyGroup> <PublishDir>$(WebOutputDir)\DASH Query Builder\</PublishDir> <ApplicationVersion>$(MajorMinorVersion).0.0</ApplicationVersion> </PropertyGroup> <Target Name="BeforeResolveReferences"> <Copy SourceFiles="$(MSBuildProjectDirectory)\DASHQueryBuilder.config" DestinationFiles="$(MSBuildProjectDirectory)\app.config" /> </Target> </Project>

    Read the article

  • Template problems: No matching function for call

    - by Nick Sweet
    I'm trying to create a template class, and when I define a non-member template function, I get the "No matching function for call to randvec()" error. I have a template class defined as: template <class T> class Vector { T x, y, z; public: //constructors Vector(); Vector(const T& x, const T& y, const T& z); Vector(const Vector& u); //accessors T getx() const; T gety() const; T getz() const; //mutators void setx(const T& x); void sety(const T& y); void setz(const T& z); //operations void operator-(); Vector plus(const Vector& v); Vector minus(const Vector& v); Vector cross(const Vector& v); T dot(const Vector& v); void times(const T& s); T length() const; //Vector<T>& randvec(); //operators Vector& operator=(const Vector& rhs); friend std::ostream& operator<< <T>(std::ostream&, const Vector<T>&); }; and the function in question, which I've defined after all those functions above, is: //random Vector template <class T> Vector<double>& randvec() { const int min=-10, max=10; Vector<double>* r = new Vector<double>; int randx, randy, randz, temp; const int bucket_size = RAND_MAX/(max-min +1); temp = rand(); //voodoo hackery do randx = (rand()/bucket_size)+min; while (randx < min || randx > max); r->setx(randx); do randy = (rand()/bucket_size)+min; while (randy < min || randy > max); r->sety(randy); do randz = (rand()/bucket_size)+min; while (randz < min || randz > max); r->setz(randz); return *r; } Yet, every time I call it in my main function using a line like: Vector<double> a(randvec()); I get that error. However, if I remove the template and define it using 'double' instead of 'T', the call to randvec() works perfectly. Why doesn't it recognize randvec()? P.S. Don't mind the bit labeled voodoo hackery - this is just a cheap hack so that I can get around another problem I encountered.

    Read the article

  • algorithm q: Fuzzy matching of structured data

    - by user86432
    I have a fairly small corpus of structured records sitting in a database. Given a tiny fraction of the information contained in a single record, submitted via a web form (so structured in the same way as the table schema), (let us call it the test record) I need to quickly draw up a list of the records that are the most likely matches for the test record, as well as provide a confidence estimate of how closely the search terms match a record. The primary purpose of this search is to discover whether someone is attempting to input a record that is duplicate to one in the corpus. There is a reasonable chance that the test record will be a dupe, and a reasonable chance the test record will not be a dupe. The records are about 12000 bytes wide and the total count of records is about 150,000. There are 110 columns in the table schema and 95% of searches will be on the top 5% most commonly searched columns. The data is stuff like names, addresses, telephone numbers, and other industry specific numbers. In both the corpus and the test record it is entered by hand and is semistructured within an individual field. You might at first blush say "weight the columns by hand and match word tokens within them", but it's not so easy. I thought so too: if I get a telephone number I thought that would indicate a perfect match. The problem is that there isn't a single field in the form whose token frequency does not vary by orders of magnitude. A telephone number might appear 100 times in the corpus or 1 time in the corpus. The same goes for any other field. This makes weighting at the field level impractical. I need a more fine-grained approach to get decent matching. My initial plan was to create a hash of hashes, top level being the fieldname. Then I would select all of the information from the corpus for a given field, attempt to clean up the data contained in it, and tokenize the sanitized data, hashing the tokens at the second level, with the tokens as keys and frequency as value. I would use the frequency count as a weight: the higher the frequency of a token in the reference corpus, the less weight I attach to that token if it is found in the test record. My first question is for the statisticians in the room: how would I use the frequency as a weight? Is there a precise mathematical relationship between n, the number of records, f(t), the frequency with which a token t appeared in the corpus, the probability o that a record is an original and not a duplicate, and the probability p that the test record is really a record x given the test and x contain the same t in the same field? How about the relationship for multiple token matches across multiple fields? Since I sincerely doubt that there is, is there anything that gets me close but is better than a completely arbitrary hack full of magic factors? Barring that, has anyone got a way to do this? I'm especially keen on other suggestions that do not involve maintaining another table in the database, such as a token frequency lookup table :). This is my first post on StackOverflow, thanks in advance for any replies you may see fit to give.

    Read the article

  • What is the base open source java package to filter/match URLs?

    - by Boaz
    Hi, I have an high performance application which deals with URLs. For every URL it needs to retrieve the appropriate settings from a predefined pool. Every settings object is associated with a URL pattern which indicates which URLs should use these settings. The matching rules are as follows: "google.com" match pattern should match all URLs pointing to the google domain (thus, maps.google.com and www.google.com/match are matched). "*.google.com" should match all URLs pointing to a subdomain of google.com (thus, maps.google.com matches, but google.com and www.google.com don't). "maps.google.com" should match all URLs pointing to this specific subdomain. Apart from the above rules, every match rule can contain a path, which means that the path part of the URL should start with the match rule path. So: "*.google.com/maps" matches "maps.google.com/maps" but not "maps.google.com/advanced". As you can see the rules above are overlapping. In the case two rules exist which match the same URL the most specific should apply. The list above is ranked from least specific to most specific. This seems to be such a standard problem that I was hoping to use a ready made library rather than program my self. Google reveals a couple of options but without a clear way to choose between them. What would you recommend as a good library for this task? Thanks, Boaz

    Read the article

  • F# How to tokenise user input: separating numbers, units, words?

    - by David White
    I am fairly new to F#, but have spent the last few weeks reading reference materials. I wish to process a user-supplied input string, identifying and separating the constituent elements. For example, for this input: XYZ Hotel: 6 nights at 220EUR / night plus 17.5% tax the output should resemble something like a list of tuples: [ ("XYZ", Word); ("Hotel:", Word); ("6", Number); ("nights", Word); ("at", Operator); ("220", Number); ("EUR", CurrencyCode); ("/", Operator); ("night", Word); ("plus", Operator); ("17.5", Number); ("%", PerCent); ("tax", Word) ] Since I'm dealing with user input, it could be anything. Thus, expecting users to comply with a grammar is out of the question. I want to identify the numbers (could be integers, floats, negative...), the units of measure (optional, but could include SI or Imperial physical units, currency codes, counts such as "night/s" in my example), mathematical operators (as math symbols or as words including "at" "per", "of", "discount", etc), and all other words. I have the impression that I should use active pattern matching -- is that correct? -- but I'm not exactly sure how to start. Any pointers to appropriate reference material or similar examples would be great.

    Read the article

  • Optimizing a "set in a string list" to a "set as a matrix" operation

    - by Eric Fournier
    I have a set of strings which contain space-separated elements. I want to build a matrix which will tell me which elements were part of which strings. For example: "" "A B C" "D" "B D" Should give something like: A B C D 1 2 1 1 1 3 1 4 1 1 Now I've got a solution, but it runs slow as molasse, and I've run out of ideas on how to make it faster: reverseIn <- function(vector, value) { return(value %in% vector) } buildCategoryMatrix <- function(valueVector) { allClasses <- c() for(classVec in unique(valueVector)) { allClasses <- unique(c(allClasses, strsplit(classVec, " ", fixed=TRUE)[[1]])) } resMatrix <- matrix(ncol=0, nrow=length(valueVector)) splitValues <- strsplit(valueVector, " ", fixed=TRUE) for(cat in allClasses) { if(cat=="") { catIsPart <- (valueVector == "") } else { catIsPart <- sapply(splitValues, reverseIn, cat) } resMatrix <- cbind(resMatrix, catIsPart) } colnames(resMatrix) <- allClasses return(resMatrix) } Profiling the function gives me this: $by.self self.time self.pct total.time total.pct "match" 31.20 34.74 31.24 34.79 "FUN" 30.26 33.70 74.30 82.74 "lapply" 13.56 15.10 87.86 97.84 "%in%" 12.92 14.39 44.10 49.11 So my actual questions would be: - Where are the 33% spent in "FUN" coming from? - Would there be any way to speed up the %in% call? I tried turning the strings into factors prior to going into the loop so that I'd be matching numbers instead of strings, but that actually makes R crash. I've also tried going for partial matrix assignment (IE, resMatrix[i,x] <- 1) where i is the number of the string and x is the vector of factors. No dice there either, as it seems to keep on running infinitely.

    Read the article

  • Optimizing near-duplicate value search

    - by GApple
    I'm trying to find near duplicate values in a set of fields in order to allow an administrator to clean them up. There are two criteria that I am matching on One string is wholly contained within the other, and is at least 1/4 of its length The strings have an edit distance less than 5% of the total length of the two strings The Pseudo-PHP code: foreach($values as $value){ foreach($values as $match){ if( ( $value['length'] < $match['length'] && $value['length'] * 4 > $match['length'] && stripos($match['value'], $value['value']) !== false ) || ( $match['length'] < $value['length'] && $match['length'] * 4 > $value['length'] && stripos($value['value'], $match['value']) !== false ) || ( abs($value['length'] - $match['length']) * 20 < ($value['length'] + $match['length']) && 0 < ($match['changes'] = levenshtein($value['value'], $match['value'])) && $match['changes'] * 20 <= ($value['length'] + $match['length']) ) ){ $matches[] = &$match; } } } I've tried to reduce calls to the comparatively expensive stripos and levenshtein functions where possible, which has reduced the execution time quite a bit. However, as an O(n^2) operation this just doesn't scale to the larger sets of values and it seems that a significant amount of the processing time is spent simply iterating through the arrays. Some properties of a few sets of values being operated on Total | Strings | # of matches per string | | Strings | With Matches | Average | Median | Max | Time (s) | --------+--------------+---------+--------+------+----------+ 844 | 413 | 1.8 | 1 | 58 | 140 | 593 | 156 | 1.2 | 1 | 5 | 62 | 272 | 168 | 3.2 | 2 | 26 | 10 | 157 | 47 | 1.5 | 1 | 4 | 3.2 | 106 | 48 | 1.8 | 1 | 8 | 1.3 | 62 | 47 | 2.9 | 2 | 16 | 0.4 | Are there any other things I can do to reduce the time to check criteria, and more importantly are there any ways for me to reduce the number of criteria checks required (for example, by pre-processing the input values), since there is such low selectivity?

    Read the article

  • Optimising ruby regexp -- lots of match groups

    - by Farcaller
    I'm working on a ruby baser lexer. To improve performance, I joined up all tokens' regexps into one big regexp with match group names. The resulting regexp looks like: /\A(?<__anonymous_-1038694222803470993>(?-mix:\n+))|\A(?<__anonymous_-1394418499721420065>(?-mix:\/\/[\A\n]*))|\A(?<__anonymous_3077187815313752157>(?-mix:include\s+"[\A"]+"))|\A(?<LET>(?-mix:let\s))|\A(?<IN>(?-mix:in\s))|\A(?<CLASS>(?-mix:class\s))|\A(?<DEF>(?-mix:def\s))|\A(?<DEFM>(?-mix:defm\s))|\A(?<MULTICLASS>(?-mix:multiclass\s))|\A(?<FUNCNAME>(?-mix:![a-zA-Z_][a-zA-Z0-9_]*))|\A(?<ID>(?-mix:[a-zA-Z_][a-zA-Z0-9_]*))|\A(?<STRING>(?-mix:"[\A"]*"))|\A(?<NUMBER>(?-mix:[0-9]+))/ I'm matching it to my string producing a MatchData where exactly one token is parsed: bigregex =~ "\n ... garbage" puts $~.inspect Which outputs #<MatchData "\n" __anonymous_-1038694222803470993:"\n" __anonymous_-1394418499721420065:nil __anonymous_3077187815313752157:nil LET:nil IN:nil CLASS:nil DEF:nil DEFM:nil MULTICLASS:nil FUNCNAME:nil ID:nil STRING:nil NUMBER:nil> So, the regex actually matched the "\n" part. Now, I need to figure the match group where it belongs (it's clearly visible from #inspect output that it's _anonymous-1038694222803470993, but I need to get it programmatically). I could not find any option other than iterating over #names: m.names.each do |n| if m[n] type = n.to_sym resolved_type = (n.start_with?('__anonymous_') ? nil : type) val = m[n] break end end which verifies that the match group did have a match. The problem here is that it's slow (I spend about 10% of time in the loop; also 8% grabbing the @input[@pos..-1] to make sure that \A works as expected to match start of string (I do not discard input, just shift the @pos in it). You can check the full code at GH repo. Any ideas on how to make it at least a bit faster? Is there any option to figure the "successful" match group easier?

    Read the article

  • Sed: regular expression match lines without <!--

    - by sixtyfootersdude
    I have a sed command to comment out xml commands sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml Takes: <a> <!-- Comment --> <b> bla </b> </a> Produces: <!-- Security: <a> --> <!-- Security: <!-- Comment --> --> // NOTE: there are two end comments. <!-- Security: <b> --> <!-- Security: bla --> <!-- Security: </b> --> <!-- Security: </a> --> Ideally I would like to not use my sed script to comment things that are already commented. Ie: <!-- Security: <a> --> <!-- Comment --> <!-- Security: <b> --> <!-- Security: bla --> <!-- Security: </b> --> <!-- Security: </a> --> I could do something like this: sed 's/^\([ \t]*\)\(.*[0-9a-zA-Z<].*\)$/\1<!-- Security: \2 -->/' web.xml sed 's/^[ \t]*<!-- Security: \(<!--.*-->\) -->/\1/' web.xml but I think a one liner is cleaner (?) This is pretty similar: http://stackoverflow.com/questions/436850/matching-a-line-that-doesnt-contain-specific-text-with-regular-expressions

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >