How do I write a Graql query that looks for for an attribute between two dates? - vaticle-typedb

I have the following question I want to ask in Graql: "Give me every person who was born between June 1999 and September 1999"
I have tried writing it like this but I don't think this is right?
match
$p isa person, has age $a;
{$a contains "June";} or {$a contains "September"};
$a contains "1999"; get;

Try adding a semicolon after "September"!

Related

R searching for specific string patterns (part 2)

I have a previous question listed here (Searching for specific string pattern) but there are some additional questions that I have.
Previously, I thought my file naming convention was only of these formats:
"aaaaa-ttttt-eeee-q4-2015-file"
"aaaaaa-fffff-3333-q2-2012-file"
or specifically, it is the quarter followed by "-" then year.
However, upon further investigation, the files have other variations such as:
"aaaaaa-f2q09-bbbbb"
"aaaaaa-f2q2008-bbbbb"
"aaaaaa-f4q-2008-fffff"
"f4q-aaaaa-eeeeee-2008"
"q2-aaaaaaaaa-eeeeeee-2005"
"aaaaaaaa-3q-2008-rrrrrrr"
Similarly for all the above, I would like to extract the year and quarter, and I'm not sure if there is a general code that I can write that can extract them all at one go or do i have to write a few sets of code and run them by waves. Not very familiar with sub function in R and would actually appreciate if someone can point me to a website that has detailed explanations and examples for me to write my own code to extract these info.
Ultimately, the code should parse all those strings and output something like: year = 2005, quarter = q4 etc.
Try this it uses regexpr to show the location of the match and regmatches to return them, it is very susceptible to pull out incorrect data. For quarter it will return any instance of 1-4 either followed or preceded by a q. If there is any other information that can make these more specific matches than I suggest including them.
input=c("aaaaaa-f2q09-bbbbb",
"aaaaaa-f2q2008-bbbbb",
"aaaaaa-f4q-2008-fffff",
"f4q-aaaaa-eeeeee-2008",
"q2-aaaaaaaaa-eeeeeee-2005",
"aaaaaaaa-3q-2008-rrrrrrr")
quarter=regmatches(input, regexpr("[1-4]q|q[1-4]", input))
year = regmatches(input, regexpr("q\\d{4}|q\\d{2}|\\d{4}", input))
year = gsub("q","",year)
year = sub("\\b(\\d{2})\\b","20\\1", year)
There are lots of issues with the year matching also, because you have three different formats that are possible "q09", "q2008", "2008". Because the function returns the first match in the string the q\d{4} is needed to pull back the q2008 example.
My sub function here subs that matching regular expression with 20 and the matching expression itself, the \\1 is returning the stuff in brackets (\\d{2})
Test it and comment any mistakes

Query first letters of each words and full text search in one query

Suppose I have such data:
Lena
Lera
Elena
Mark
Allen
Paul
When user enters 'le' I need to return
Find words by first letters
After that should follow all another words that contains 'le' chars (full text search)
So it should return:
Lena
Lera
Alen
Elena
Something like that (this example does not return anything):
SELECT name FROM table WHERE name LIKE 'le%' AND like '%le%' ORDER BY name ASC
Thank you.
After it turns out that UNION mixes up the order of the sub selects, we'll try something else. You could try it with a custom ORDER BY. First order by whether it starts with your search term, then by name.
SELECT name
FROM table
WHERE UPPER(name) LIKE UPPER('%le%')
ORDER BY (CASE WHEN UPPER(name) LIKE UPPER('le%') THEN 1 ELSE 2 END),
name ASC
Comparing the strings with UPPER helps ignoring the case. But UPPER only support ASCII apparently, read this article for more information on the topic. It also contains other ways to ignore case when comparing strings.

owl datetime restriction creater than

I have a class and i make it equivelent to this restriction
Rates and createdOn value "2016-01-01T09:00:00+00:00"^^dateTime
where Rates is a class and createdOn is a data type property has domain as a date time
what i did is not what i want to do because i want to say something like:
all the dates that are greater than 2016 january first
i though that could be done by two ways but i don't know if owl support any of them
first i thought :
Rates and createdOn value > "2016-01-01T09:00:00+00:00"^^dateTime
but protege told me that we can't put >
then i though that if there is a way to just check the year of the date, but also i don't know how to do that
could you help please ?
You need to use a DatatypeRestriction:
Declaration(Class(example:Rates))
Declaration(DataProperty(example:createdOn))
Declaration(Datatype(xsd:dateTime))
DataPropertyRange(example:createdOn DatatypeRestriction(xsd:dateTime xsd:minInclusive "2016-01-01T00:00:00"^^xsd:dateTime))
SubClassOf(DataSomeValuesFrom(example:createdOn rdfs:Literal) example:Rates)
Edit: In Manchester syntax, these facets are written like this:
Class: <http://example.org#Rates>
SubClassOf:
<http://example.org#createdOn> some xsd:dateTime[>= "2016-01-01T00:00:00"^^xsd:dateTime]

MDX Compare DateTime attribute

I´m new to MDX and I have a simple question. I work with the TFS Cube it is named as Team System. My problem:
I have an IIF expression where I want to check additional my expression with an AND operator. There I want to compare two DateTime objects. The report should only show me the data from the actual date. Here my code:
IIF(ISEMPTY(SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]))
AND[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember < Now()
, [Measures].[EffectivelyValue]
, SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]) )
Planned Week is a self created field which has the DateTime datatype. The Now() function has also a DateTime datatype so the comparision should be right but it happens nothing.
Thanking you in anticipation
Eugen
Hierarchy members in MDX have a data type of 'member', and do not have a 'primitive' data type like datetime, string, or integer. Only member properties have 'primitive' data types. You could either define a property like datetime of your week attribute. Assuming you are SQL Server Analysis Services, this would be done via relationships.
Or you could use string operations to extract the date information from the UniqueName property which avoids having to change the cube. The UniqueName contains the data that you defined as the key in your cube design. Assuming your week hierarchy members have a key from which you can extract something like 20130820 for August 20, 3013 via string functions (I just will use Mid(, 30, 8) as an example below), you could do something like
CLng(Mid([Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName, 30, 8))
<
CLng(Format(Now(), "yyyymmdd"))
You will have to check what exactly the CurrentMember.UniqueName shows in your cube to adapt the above code.
And finally, you could of course also use string methods to extract the relevant parts from the UniqueName and then the CDate function on that to compare to an unchanged Now(), i. e. do all operations on the left side of the <.
Hello thank you very much for you answer. I tried:
Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10)
shows e.g. 2013-07-21, 2013-07-28 (it shows the week endings)
so I tried this:
AND CLng(Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10))
<CLng(Format(Now(), "yyyy-mm-dd"))
But it happens nothing. If I execute it in a single way it shows everywhere "true". But I have datasets with dates which are e.g. > 2013-08-23. So there should be false values too.
EDIT: OK I solved the problem. The
Format(Now(), "yyyy-mm-dd")
must be
Format(Now(), "yyyy-MM-dd")

Have wp_get_archives return a string with no year in it

Currently I use wp_get_archives to return the year.
I then call it again with the monthly arg to display the months.
It displays similarly to this, though I am not sure it will work when we are in a different year:
2011
April 2011(1)
March 2011(12)
I want a display like this
2012(when we reach it)
December(8)
November(5)
2011
April(1)
March(12)
Where the number in brackets is the months post count.
Obviously this means stripping out the year from the monthly archives.
Is this possible? I'd rather not modify core wp functions and do this within the theme, I would also rather not rely on a plugin.
Thank you!
While maybe not the best way to do it, give this a try
$string = wp_get_archives('type=monthly&limit=20&echo=0');
$pattern = ' ((19|20)\d{2}(</a>))';
echo preg_replace($pattern, '\\3', $string);

Resources