This formula should filter all results between today and 7 days from now from another sheet but it gives a Formula parse error:
=QUERY(Sheet2!A3:H13;"SELECT A, B, C, D, E, F, G, H WHERE (A >= date '"&text(TODAY(),"yyyy-MM-dd")&"' AND A <= date '"&text(TODAY()+7,"yyyy-MM-dd")& "')"; false)
If I use this formula instead:
=QUERY(Sheet2!A3:H13;"SELECT A, B, C, D, E, F, G, H WHERE (A >= date '2020-11-08' AND A <= date '2020-11-15')"; false)
It works but it would need to change dates manually everytime.
Where I am wrong?
try:
=QUERY(Sheet2!A3:H13;
"where A >= date '"&TEXT(TODAY(); "yyyy-MM-dd")&"'
and A <= date '"&TEXT(TODAY()+7; "yyyy-MM-dd")&"'"; 0)
Related
I'm trying to write some rule in prolog language to change singular form to plural form and want to support to write the rule.
I assume you want to pluralize English words. One approach is to have a general rule and also some specific rules for special cases.
% special cases
pluralize(deer, deer).
pluralize(mouse, mice).
pluralize(antenna, antennae).
% general rule
pluralize(Singular, Plural) :- atom_concat(Singular, s, Plural).
This seems to be OK for some words:
?- pluralize(coin, X).
X = coins.
?- pluralize(date, X).
X = dates.
But some words seem to trip it up:
?- pluralize(fox, X).
X = foxs.
You could probably make the rule more intelligent. This is where I'd start.
list_member(X,[X|_]).
list_member(X,[_|TALL]):-list_member(X,TALL).
isVowels(A):-list_member(A,[a, e, i, o, u]),!.
isConsonants(A):-list_member(A,[b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, x, w,y,z]),!.
word:- write('Enter the word you want to know weather it followed by a an or the:.'),read(X),nl,
plular(X):-((isVowels(sub_atom(X, _, 1, 0, C)))->(write('Plular form of '),write(X),write(' is '),write(X),write('s'));(write('Plular form of '),write(X),write(' is '),write(X),write('es'))).
You can have a look on this book "Natural Language Processing for PROLOG Programmers" (Page 262-263) that describes some rules for changing singular form of a word to plural. I have written a simple program that works for nouns. I hope it helps.
morphology(W, Wo):-
(sub_atom(W,_, 2, 0, C), (C == sh; C = ch));
(sub_atom(W,_,1,0,P), (P == s; P == z; P == x)) ->
atom_concat(W,es,Wo) ;
(sub_atom(W,Q,1,0,L), (L == y)) ->
sub_atom(W,_,Q,1,L1), atom_concat(L1,ies,Wo) ;
atom_concat(W,s,Wo).
? morphology('Age', S).
S = 'Ages'.
? morphology(student, S).
S = students.
I have a Scala function that does 2-3 recursive calls through its lifetime. I want to save the variable inside the second tuple in a list. Is there a smart way to do this?
Just passing the variable around would mean that I would have a List[String], when in actuality what I want is a List[List[String]].
Would there be a need for a variable inside the function that updated with each itteration?
def someRecursiveFunction(listOfWords:List[String])List[List[String]] = {
val textSplitter = listOfWords.lastIndexOf("Some Word")
if (Some Word != -1) {
val someTuple = listofWords.splitAt(textSplitter)
val valueIwant = someTuple._2
someRecursiveFunction(someTuple._1)
}
List(someTuple._2,someTuple._2(1),someTuple._2(2)) // What I want back
}
Is there a way to extract the second tuple out of the recursive function so that I can use it further on in my program?
If the return type is fixed to be List[List[String]], the following changes to be made
to the code :
Because someType._2 is accessed as someType._2(2), there should be at least
3 strings in someType._2 list.
The last expression to be must of return type ie., List[List[String]]. Because someType._2(1)
and someType._2(2) are just strings and not List[String]:
List(someTuple._2,List(someTuple._2(1),someTuple._2(2))) will be of return type
List[List[String]]
The value of "Some Word" will be changing in the recursive process duly noting
that the someTuple._2.size is always >=3.
As we need to access someType._2 and it will be changing during each recursion,
it is declared as var within the recursive function.
With this understanding drawn from your requirement, the following code may be
what you are looking for:
def someRecursiveFunction(listOfWords:List[String],sw: String):List[List[String]] = {
val textSplitter = listOfWords.lastIndexOf(sw)
var i =0
if(i==0) { var someTuple:(List[String],List[String]) = (List(),List()) }
if (textSplitter != -1 && listOfWords.size-3>=textSplitter) {
someTuple = listOfWords.splitAt(textSplitter)
println(someTuple._1,someTuple._2) // for checking recursion
if( someTuple._1.size>=3){ i+=1
someRecursiveFunction(someTuple._1,someTuple._1(textSplitter-3))}
}
List(someTuple._2,List(someTuple._2(1),someTuple._2(2))) // What I want back
}
In Scala REPL:
val list = List("a","b","c","x","y","z","k","j","g","Some Word","d","e","f","u","m","p")
scala> val list = List("a","b","c","x","y","z","k","j","g","Some Word","d","e","f","u","m","p")
list: List[String] = List(a, b, c, x, y, z, k, j, g, Some Word, d, e, f, u, m, p)
scala> someRecursiveFunction(list,"d")
(List(a, b, c, x, y, z, k, j, g, Some Word),List(d, e, f, u, m, p))
(List(a, b, c, x, y, z, k),List(j, g, Some Word))
(List(a, b, c, x),List(y, z, k))
(List(a),List(b, c, x))
res70: List[List[String]] = List(List(b, c, x), List(c, x))
scala> someRecursiveFunction(list,"Some Word")
(List(a, b, c, x, y, z, k, j, g),List(Some Word, d, e, f, u, m, p))
(List(a, b, c, x, y, z),List(k, j, g))
(List(a, b, c),List(x, y, z))
(List(),List(a, b, c))
res71: List[List[String]] = List(List(a, b, c), List(b, c))
Is there anyway to write the following function more elegantly?
I can see some patterns but I'm not sure how to abstract them or how to find a simpler way to write the function.
type HasRemainder = Boolean
tomorrow :: Date -> Date
tomorrow date = unsafePartial $ canonicalDate y (fst m) (fst d)
where d :: Tuple Day HasRemainder
d = case toEnum $ 1 + fromEnum (day date) of
Just v -> Tuple v false
Nothing -> Tuple (unsafePartial $ fromJust $ toEnum 1) true
m :: Tuple Month HasRemainder
m = if snd d then
case toEnum $ 1 + fromEnum (month date) of
Just v -> Tuple v false
Nothing -> Tuple (unsafePartial $ fromJust $ toEnum 1) true
else Tuple (month date) false
y :: Year
y = if snd m then
case toEnum $ 1 + fromEnum (year date) of
Just v -> v
-- use 2018 arbitrarly if the conversion from int to Date fails
Nothing -> unsafePartial $ fromJust $ toEnum 2018
else (year date)
I'd do something like this:
import Data.DateTime as DT
import Data.Maybe (maybe)
import Data.Time.Duration (Days(..))
tomorrow :: DT.Date -> DT.Date
tomorrow dt = maybe dt DT.date $ DT.adjust (Days 1.0) (DT.DateTime dt bottom)
Although it will return the input date in the unlikely event that the given date is top (which is 31st December 275759 if I remember correctly).
There is an adjust function for Time and DateTime so it's just an oversight that Date is missing one.
I would try something along those lines
getDatePart datepart defaultval1 defaultval2 =
case toEnum $ defaultval1 + fromEnum datepart of
Just v -> Tuple v false
Nothing -> Tuple (unsafePartial $ fromJust $ toEnum defaultval2) true
getDatePartDefault d datepart defaultval1 defaultval2 =
if snd d then
getDatePart datepart defaultval1 defaultval2
else Tuple datepart false
tomorrow :: Date -> Date
tomorrow date = unsafePartial $ canonicalDate (fst y) (fst m) (fst d)
where d :: Tuple Day HasRemainder
d = getDatePart (day date) 1 1
m :: Tuple Month HasRemainder
m = getDatePartDefault d (month date) 1 1
y :: Tuple Year HasRemainder
y = getDatePartDefault d (year date) 1 2018
Take care: this is not tested
Using succ from Enum:
import Data.Date (Date)
import Data.Enum (succ)
import Data.Maybe (Maybe)
today :: Date
today = ...
tomorrow :: Maybe Date
tomorrow = succ today
I have this database:
R(A, B, C, D, E)
Keys: A
F = {A -> B, D -> E, C -> D}
I normalize it into 3NF like this:
R(A, B, C, D, E)
Keys: AD
F = {AD -> B, AD -> E, C -> D}
What I do is when I check D -> E, D is not a superkey and E is not a key attribute, so I treat D and A as a superkey {AD}. When I check C -> D, C is not a key but D is a key attribute so it's OK.
Is my normalization correctly?
There is a problem in your input data. If the relation R has the dependencies F = {A -> B, D -> E, C -> D}, then A cannot be a key. In fact, a key is a set of attributes whose closure determines all the attributes of the relation, which is not the case here, since:
A+ = AB
From F, the (only) possible key is AC, in fact
AC+ = ABCD
Normalizing means to reduce the redundancy by decomposing a relation in other relations in which the functional dependencies do not violate the normal form, and such that joining the decomposed relations, one can obtain the original one.
In you solution, you do not decompose the relation, but only change the set of dependencies with other dependencies not implied by the first set.
A correct decomposition would be instead the following:
R1 < (A B) ,
{ A → B } >
R2 < (C D) ,
{ C → D } >
R3 < (D E) ,
{ D → E } >
R4 < (A C) ,
{ } >
The algorithm to decompose a relation into 3NF can be found on any good book on databases.
I am trying to better understand boolean equivalence but this example has me a little stuck.
I am referring to this website: http://chortle.ccsu.edu/java5/Notes/chap40B/ch40B_9.html
It makes sense, but doesn't at the same time... it says that they are equivalent, but the true/false values don't add up/align in a way that makes them out to be equivalent as the table shows they are. Could someone explain this to me?
!(A && B) <-- first expression
(C || D) <-- second expression
The last columns refers to the equivalency of the two expressions, which yes, they are equivalent according to the table. However, I just don't get how the two expressions are equivalent. If A = F, B = F --> T, wouldn't C = F, D = F --> T as well?
A B C D
--------------------
F F T T T
F T T F T
T F F T T
T T F F F
You are confusing yourself when trying to reduce it from the actual expression to single letter variables. On referring the actual link, it would appear that the variables you use can be mapped to the original expressions as follows:
A = speed > 2000
B = memory > 512
C = speed <= 2000
D = memory <= 512
If you look at it, C equals !A and D equals !B. So the expression (C || D) is effectively !((!A) || (!B)). By De Morgan's Law, that is the same as !(A && B).
This table is explaining that !(A && B) is equivalent to !A || !B. The columns C and D appear to be defined as C = !A and D = !B. The last column is C || D
So A = F, B = F certainly implies !(A && B). In this case C = D = T, and so also C || D = T.