I am trying to query and then filter my results based on the drop down in N4
=
IF(and(N4="ALL"), query(Vendors!1:1000,"select A, B, C, D, E, F, G, H, I, J, K, L", 2),
IF(and(N4="Trained"), query(Vendors!1:1000,"select A, B, C, D, E, F, G, H, I, J, K, L", 2),
IF(and(N4="Requested"), query(Vendors!1:1000,"select A, B, C, D, E, F, G, H, I, J, K, L", 2),
IF(and(N4="Invited"), query(Vendors!1:1000,"select A, B, C, D, E, F, G, H, I, J, K, L", 2)))))
Those all return results. However, now I need help omitting the results that dont match the dropdown.
Sorry I didn't read it correctly. Try this.
=IF (N4 <>"ALL",IF(OR(OR( N4="Trained",N4="Requested",N4="Invited")),query(Vendors!1:1000,"select A, B, C, D, E, F, G, H, I, J, K, L where A = '"& N4 &"'")),query(Vendors!2:1000,"select A, B, C, D, E, F, G, H, I, J, K, L where A<>''"))
Key in the Header row. Change Column A to whatever column "Trained", "Invited", etc are in.
Related
Example: Suppose we choose the ordering M, J, A, B, E
P(J | M) = P(J)? No
P(A | J, M) = P(A | J)? P(A | J, M) = P(A)? No
How do you know that P(A|J, M) = P(A) is the only condition that A depends on M? Is it possible that only J is dependent on A?
I have a problem with the following QUERY code in Google Sheets.
All rows work fine accept the first row. Column BY crashes the code. When i change the column to BZ it works fine, but that's not the data i need. What am i doing wrong?
The error i get:
Error
In ARRAY_LITERAL, an Array Literal was missing values for one or more rows.
QUERY({
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, BR, E, F, BT, BY, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, BJ, E, F, BL, BQ, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, BB, E, F, BD, BI, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, AT, E, F, AV, BA, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, AL, E, F, AN, AS, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, AD, E, F, AF, AK, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, V, E, F, X, AC, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, N, E, F, P, U, I, H")
},"select Col1, Col2, Col3, Col4, Col5, Col6, Col7,Col8 WHERE Col2 is not null ORDER BY Col1")
The BY is a keyword for the query language. You have to escape it to use it as a parameter of your query. Use the backquote (`) symbol to escape the column name in your query formula:
=QUERY({
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, BR, E, F, BT, `BY`, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, BJ, E, F, BL, BQ, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, BB, E, F, BD, BI, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, AT, E, F, AV, BA, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, AL, E, F, AN, AS, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, AD, E, F, AF, AK, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, V, E, F, X, AC, I, H");
QUERY('Form Responses 1'!$A$2:$CS$1051, "select A, N, E, F, P, U, I, H")
},"select Col1, Col2, Col3, Col4, Col5, Col6, Col7,Col8 WHERE Col2 is not null ORDER BY Col1")
I am trying to find all the paths in a graph with minimum distance using DLV. Say I have the following graph:
I am expecting to obtain the predicates (I hope I don't skip any):
path(a, b, 1), path(a, d, 1), path(a, e, 1), path(a, c, 2)
path(b, a, 1), path(b, c, 1), path(d, d, 2), path(b, e, 2)
path(c, b, 1), path(c, e, 1), path(c, a, 2), path(c, d, 3)
path(d, a, 1), path(d, b, 2), path(d, e, 2), path(d, c, 3)
path(e, a, 1), path(e, c, 1), path(e, d, 2), path(e, b, 2)
I assume that you can travel an arch both left or right. So, I tried the following:
path(X, Y, 1) :- arc(X, Y).
path(Y, X, 1) :- arc(X, Y).
path(X, Z, L) :- path(X, Y, M), path(Y, Z, N),
X!=Z,
L = M + N,
not path(X, Z, V), V < L, #int(V)
The idea of the third rule was to add 2 existing paths if they are not going back (X!=Z) and there is not already a path connecting the same edges with a shorter distance (not path(X, Z, V), V < L, #int(V)). I had to add #int(V) because otherwise the rule was not safe. I don't know if there is a better way of resolving this safety issue with an integer value.
When I run this code (with the flag -N=5 to set #maxint=5) I get paths that should not be there, for example, path(d,a,5). I don't know if the problem is with the #int(V) or something else but I wouldn't expect these paths to appear since I already have a path(d,a,1). Probably it is because of #int(V) but I can't figure out how to do this right.
Can anyone help me solve this? Thanks in advance.
Solution to the problem using lists to keep track of the path:
path(X, Y, [X, Y], 1) :- arc(X, Y).
path(Y, X, [Y, X], 1) :- arc(X, Y).
path(X, Z, P, D) :- path(X, Y, P1, D1),
path(Y, Z, P2, 1),
#insLast(P1, Z, P),
D = D1 + 1,
not #member(Z, P1).
shortest_path(X, Y, D) :- node(X), node(Y),
#min{L: path(X, Y, P, L)} = D.
Solution without the need of lists (with the help of CapelliC)
path(X, Y, 1) :- arc(X,Y).
path(Y, X, 1) :- arc(X,Y).
path(X, Y, D) :- path(X,Z,D0), arc(Z,Y),
#count{A: node(A)} = Max,
D0<Max, X != Y,
D = D0+1.
shorter_paths(X, Y, D) :- node(X), node(Y),
#min{L: path(X, Y, L)} = D.
Note that we need to define all nodes with a predicate node() and that the predicate arc() assumes that the edge of the graph is bidirectional.
examples/spaths.dl from DES distribution. See the commented code below... -
%
% Shortest Paths in a Graph
%
% Datalog Formulation
%
% Program: Shortest paths in a graph
% Author : Fernando Sáenz-Pérez
% Date : September, 2009
edge(a,b).
edge(a,c).
edge(b,a).
edge(b,d).
path(X,Y,1) :-
edge(X,Y).
path(X,Y,L) :-
path(X,Z,L0),
edge(Z,Y),
count(edge(A,B),Max),
L0<Max,
L is L0+1.
spaths(X,Y,L) :-
min(path(X,Y,Z),Z,L).
% Note that the following is not stratifiable in DES
%sp(X,Y,1) :-
% edge(X,Y).
%sp(X,Y,L) :-
% sp(X,Z,L0),
% not(shorter(X,Z,L0)),
% edge(Z,Y),
% L is L0+1.
%shorter(X,Y,L) :-
% sp(X,Y,L0),
% L0<L.
I would like to use Prolog to parse the following grammar:
E -> E + T | E - T |T
T -> T * F | T / F | F
F -> ( E ) | number | letter
Here's a test case that should be true (My problem is that it is currently coming out as false):
e([ 34 , *, '(', 45, +, b, ')']).
i.e. 34 * (45 + b)
And here is my attempt:
e(X) :- append(List1, [+ | List2], X), e(List1), t(List2).
e(X) :- append(List1, [- |List2], X), e(List1), t(List2).
t(X) :- append(List1, [* | List2], X), t(List1), f(List2).
t(X) :- append(List1, [/ | List2], X), t(List1), f(List2).
t(X) :- f(X).
f(X) :- append(['(' | List], [')'], X), e(List).
letter(X) :- member(X, [a, b, c, d, e, f, g, h, i, j, k, l, m,
n, o, p, q, r, s, t, u, v, w, x, y, z]).
f([X]) :- number(X).
f([X]) :- letter(X).
I've been trying to make a parser for a (very) simple language that looks like this:
block{you are a cow too blkA{ but maybe not} and so is he} hear me moo blockZ{moooooo}
I can break it apart using regexes:
.*?[^ ]*?\\{
.*?\\}
which would essentially keep eating characters until it found something that matches [^ ]*?\\{ or \\}: the start or end of a block. My question is, if I want to do it using Scala's Parser Combinators, how do I do that? I currently have:
def expr: Parser[Any] = (block | text)+
def text = ".+?".r
def block = "[^ ]*?\\{".r ~ expr ~ "}"
but this doesn't work:
parsed: List(b, l, o, c, k, {, y, o, u, a, r, e, a, c, o, w, t, o, o, b, l, k, A, {, b, u, t, m, a, y, b, e, n, o, t, }, a, n, d, s, o, i, s, h, e, }, h, e, a, r, m, e, m, o, o)
It seems that the block parser is not firing, and so the text parser is being fired repeatedly. but when i remove the text parser:
def expr: Parser[Any] = (block)+
I get:
failure: string matching regex `[^ ]*?\{' expected but `y' found
block{you are a cow too blkA{ but maybe not} and so is he} hear me moo
^
So obviously the block parser does work, except not when the text parser is present. What's happening? and is there a "proper" way of doing this, for so basic a grammar?
EDIT: Changed the title, since it's not so much about the reluctance anymore as just solving the problem
EDIT: I now have this:
def expr: Parser[Any] = (block | text)+
def text = "[^\\}]".r
def block = "[^ ]*?\\{".r ~ expr ~ "}"
The logic behind this is that for each character, it tests whether or not it is the start of a block. If it isn't, it moves on to the next character. This gives me:
parsed: List(((block{~List(y, o, u, a, r, e, a, c, o, w, t, o, o, ((blkA{~List(b, u, t, m, a, y, b, e, n, o, t))~}), a, n, d, s, o, i, s, h, e))~}), h, e, a, r, m, e, m, o, o)
which is kind of correct. It is parsing the non-block characters one-by-one though, which is probably a performance problem (i think?). Is there any way to parse all those non-block characters at once and leave them in one big string?
The problem is that text is consuming all closing curly braces (}). It goes like this:
expr -> block -> expr -> text.+ (until all input is consumed)
At this point, it exits expr and tries to parse }, which does not exists, fails, and falls back to text on the first expr.
You can use log to see what's going on when you parse.