pattern-matching

Why are variables not allowed in alternative patterns?

核能气质少年 提交于 2019-12-06 17:15:31
问题 Often you have "symmetric" matches and want to write things like: def g(p:(Int,Int)) = p match { case (10,n) | (n,10) => println(n) case _ => println("nope") } This is not allowed, but if every alternative has the same variables with the same types , this shouldn't be a problem, as it could be translated to separate cases: def g(p:(Int,Int)) = p match { case (10,n) => println(n) case (n,10) => println(n) case _ => println("nope") } So why do we have this restriction? 回答1: Likely because it

Extracting boundaries out of given condition in Perl [closed]

天涯浪子 提交于 2019-12-06 16:26:13
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I have a square-shape zone described by some conditions as follows: x < b && x >= a && y < d && y >= c I would like to extract the top-right and bottom-left corners coordinates. (Let's assume that the whole condition is given in $cond. Also, store the pairs in two lists @xy_b and

obtaining 2d-3d point correspondences for pnp or posit

扶醉桌前 提交于 2019-12-06 15:56:49
I am trying to estimate the pose and position of a satellite given an image of it. I have a 3D model of the satellite. Using either PnP solvers or POSIT works great when I pick out the point correspondences myself, however I need to to find a method to match the points up automatically. Using a corner detector (best one I found so far is based on the contour) I can find all the relevant points in the image in addition a few spurious points. However I need to match a given point in the image to the correct point in the 3D model. The articles I have read on the subject always seem to assume that

Regex remove all occurrences of multiple characters in a string

醉酒当歌 提交于 2019-12-06 15:42:57
In my PostgreSQL I want to replace all characters (;<>) occurrences in a string. My query: update table_name set text = regexp_replace(text, '/[(;<>)]+/g', ''); I think my regexp is wrong. Can anyone help me out with it? Use the much faster translate() for this simple case: UPDATE tbl SET text = translate(text, '(;<>)', ''); Every character in the second parameter that has no counterpart in the third parameter is replaced with nothing. The regular expression solution could look like this: regexp_replace(text, '[(;<>)]', '', 'g'); Essential element is the 4th parameter 'g' to replace "globally"

Debugging Pattern (regex) failure in in Java (Android)

柔情痞子 提交于 2019-12-06 15:14:32
I'm doing a pattern match in a piece of code that works fine in one circumstance but not another. The code is currently: DLVRYrx = Pattern.compile("(\\d+\\s\\p{Letter}+\\s\\d+)\\s(\\d+(?:\\.\\d+)?)\\s(\\d+)"); Log.d(TAG, "* Regex matched " + DLVRYrx.matcher("01 Jan 01 60.9876 1234").groupCount() + " groups"); // prints 3 as expected in logcat for (int i=19; i<(fields-6); i++) { final String DATAstr = values[i]; try { Matcher Dmatch = DLVRYrx.matcher(DATAstr); String data1 = Dmatch.group(0); } catch (IllegalStateException e) { Log.e(TAG, "! Text ["+DATAstr+"] didn't match regex"); } } The code

Case classes matching in Scala

喜欢而已 提交于 2019-12-06 14:57:15
I want to have this comparison function that matches two case classes, but it's a bit verbose. Leafs are always in the sorted order in the List. abstract class CodeTree case class Fork(left: CodeTree, right: CodeTree, chars: List[Char], weight: Int) extends CodeTree case class Leaf(char: Char, weight: Int) extends CodeTree def sortCodeTreeFun(x: CodeTree, y: CodeTree) = { (x, y) match { case (x1: Leaf, y1: Leaf) => true case (x1: Fork, y1: Leaf) => x1.weight < y1.weight case (x1: Leaf, y1: Fork) => x1.weight < y1.weight case (x1: Fork, y1: Fork) => x1.weight < y1.weight } } I tried to modify

makefile: pattern rules for subdirectory

夙愿已清 提交于 2019-12-06 14:54:29
问题 Here is my project: project |--- main.cpp |--- makefile |--- test |--- Test.cpp |--- Test.h Here is the makefile : g++1x:=g++ -std=c++14 -stdlib=libc++ -MMD -MP cflags:= -Wall -lncurses PATHS:=./ ./test/ TARGET:=matrix.out SRC:=$(foreach PATH,$(PATHS),$(wildcard $(PATH)/*.cpp)) OBJDIR:=.obj OBJ:=$(addprefix $(OBJDIR)/,$(notdir $(SRC:.cpp=.o))) .PHONY: install install: $(OBJDIR) $(TARGET) $(OBJDIR): mkdir -p $(OBJDIR) $(TARGET): $(OBJ) $(g++1x) $(cflags) -o $@ $^ -g $(OBJDIR)/%.o: %.cpp $(g+

Algorithms for Natural Language Understanding

廉价感情. 提交于 2019-12-06 14:29:12
I wanted to know what algorithms I could use for NLU? For example, let's say I want to start a program, and I have these sentences "Let us start" "Let him start" Obviously, the first sentence should start the program, but not the second one (since it doesn't make sense). Right now, I have am using Stanford's NLP API and have implemented the TokenRegexAnnotator class: CoreMapExpressionExtractor<MatchedExpression> extractor = CoreMapExpressionExtractor.createExtractorFromFile(env, "tr.txt"); So my code "knows" what "Start" should do, that is, "Start" should trigger/start the program. But "Start"

How to count occurrence of each character in java string using Pattern Class(Regex)

走远了吗. 提交于 2019-12-06 13:57:39
问题 I am trying to find a number of Occurrence of each character on the given string. Expected output: t=2 e=1 s=1 i=1 n=1 g=1 Current output: T=0 e=0 s=0 t=0 i=0 n=0 g=0 Code: String str = "Testing"; int count = 0; Pattern p = Pattern.compile("[a-zA-Z]", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(str); while (m.find()) { if (m.group().equals(str)) { count++; } System.out.println(m.group() + "=" + count); } There are many ways of doing this but I am looking for Regex only, so how can we

Regex to find html comment but not ie only comment

北战南征 提交于 2019-12-06 12:37:16
问题 I want to match valid HTML comment only using regex. I have seen many questions on stackoverflow but no one answer this. Patterns allowed to match <!-- some comments 1 --> <!-- 1.91 --> <!-- //--> <!-- --> But not these IE-only comments <!--[if IE]> <![endif]--> <!--[if !IE]><!--> <!--<![endif]--> <!--[if IE 6]> <![endif]--> What I think that it can be done by taking help of '[' if it is found as first character after <!-- it returns false. any way you can give your own solution. for php only