Need to get the current year from the system in prolog - get

I'm new to stackoverflow and to Prolog.
I want to get the current year and use it in a comparison like 'BD > currentYear'.
From the research I've been doing, I think i need to use 'use_module(library(system))' but i don't know how to...
Can you help me?
Thank you!

datime/1 in library(system) will do what you want, something like:
%% test.pl BEGIN
% Ensure datime/1 is available
:- use_module(library(system), [datime/1]).
current_year(Year) :-
datime(datime(Year,_Month,_Day,_H,_M,_S)).
%% test.pl END
You can then call current_year/1, like so:
| ?- current_year(Year), Year >= 2012, write('It is 2012 or later\n').
It is 2012 or later
Year = 2012 ?
yes
| ?-
(Note that variables in Prolog must start with an upper case letter, so currentYear is not a valid variable name.)

Related

why is output of date function on node.js server wrong?

When date was 2018-03-21 19:40, i tried following code
var date = new Date();
console.log(date);
Output :
2018-03-21T16:40:53.755Z
Server is missing for 3 hours as you see. I fixed it by adding 3 hours but I think it's not a good way. How can i fix this problem with better way ?
I don't think the date is incorrect, if you look closely at the format it is being printed, it has a Z at the end, which means:
A suffix which, when applied to a time, denotes a UTC offset of 00:00;
often spoken "Zulu" from the ICAO phonetic alphabet representation of
the letter "Z".
I guess you are in a place separated by 3 hours from UTC.
Node.js uses this format to print Date objects by default, but you can print your local time using toLocaleString():
console.log(date.toLocaleString());
Your server is most likely in another time zone.

perl variable inside a string inside back ticks

I have a filename that is formated as electric_inventory_WE_20170730_195758.dat. There is a similar file created each day. The time created may vary. I need to capture the filename with today's date, not worry about the time and end with a .dat extension.
I have created a variable for today's date. I need to use this variable inside a string inside back ticks. Something like this:
my $today = `date "+%Y%m%d"`;
my $filename = `ls electric_inventory_WE_$today*.dat`;
I cannot find a way to get this variable to work inside a string inside the back ticks. Any help would be greatly appreciated.
That is exactly how you use a variable in backticks.
I'm not sure what the actual problem is ("I cannot find a way to get this to work" is not a helpful problem description), but here's my guess:
`date ...` returns a string with a trailing newline, "\n", so the command you're actually running ends up being:
ls electric_inventory_WE_20170330
*.dat
A possible solution is to avoid using the shell (and external commands such as date and ls) at all:
use POSIX qw(strftime);
my $today = strftime "%Y%m%d", localtime;
my #candidates = glob "electric_inventory_WE_$today*.dat";
if (#candidates != 1) {
... # handle error: either 0 or more than 1 files were found
}
my $filename = shift #candidates;
Thanks to all that provided information on this and I do apologize for the cross posts. Thanks to your posts, I was able to use the following to get this to work:
my $filename="electric_inventory_WE_" . $today . "*.dat";

Simulating rolling dice on a dynamic webpage using Bash

I'm currently working on a Bash script that simulates rolling a number of 6-sided dice. This is all taking place within a virtual machine running Debian that's acting as a server. Essentially, my webpage simulates rolling the dice by using the query string to determing the number of dice to be rolled.
For instance, if my URL is http://127.0.0.1/cgi-bin/rolldice.sh?6, I want the webpage to say "You rolled 6 dice" and then, on the next line, print six numbers between 1 and 6 inclusive (that are of course "randomly" generated).
Currently, printing out the "You rolled x dice" header is working fine. However, I'm having trouble with the next part. I'm very new to Bash, so possibly the syntax or something similar is wrong with my loop. Here it is:
for i in {1..$QUERY_STRING }; do
dieRoll = $(( $RANDOM % 6 + 1))
echo $dieRoll
done
Can anyone help me figure out where I'm going wrong? I'll be happy to post the rest of rolldice.sh if needed.
Since .. requires its arguments to be literals, you have to use eval to substitute the variable:
for i in $(eval "echo {1..$QUERY_STRING}"); do
Or if you have the seq command, you can do:
for i in $(seq 1 "$QUERY_STRING")
I recommend the latter -- using eval with input from the user is very dangerous.

pocketsphinx how to determine out of grammar words

I am currently using pocketsphix demo (android and visual studio 2010) and I have configured a jsgf grammer
like this
#JSGF V1.0;
grammar Names;
public <popular> = muhammad | ahmed | maria | john | kelley | peter | jacob | jason;
Whenever I say correct name, it detects it right in most cases but when I say a name not in the list, it still matches something and I do not want that or atleast be able to detect if something was said that was not in Grammar (may be through some score or api of pocketsphinx)
I am sure pocketsphinx has it somewhere which I don't know. Please advise.
Thanks,
Ahmed
No, this feature is not implemented. For more details see
http://cmusphinx.sourceforge.net/wiki/faq#qcan_pocketsphinx_reject_out-of-grammar_words_and_noises
You can use keyword spotting mode instead to look for a list of keyphrases. You can configure activation threshold for every phrase.

Vim errorformat / efm for PL/SQL

Im trying to get the standard vim :clist, :cope functionality working with vim.
Specifically, I'm trying (and failing) to capture the filename from the compiler output.
I have the PL/SQL code compiling okay (well, when there is no errors =), and I've got errorformat picking up the error messages, line numbers and column numbers, but I can't get it to pick up the filename (which vim needs in order to be able to jump to the file).
This is the best errorformat I've been able to come up with:
:set efm=%+P[%f],%E%l/%c%m,%C%m,%Z
This is the output from the compiler. It only has the filename on the first line (which I try and pick up with the +P[%f].
output:
[code/voyager/db/db_source/pck_policy_2.pks]
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Sep 8 14:51:24 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
Warning: Package created with compilation errors.
SQL> Errors for PACKAGE PCK_POLICY_2:
LINE/COL ERROR
-------- --------------------------------------------------------------
21/7 PLS-00103: Encountered the symbol "EXP_PBIT_ID" when expecting
one of the following:
:= . ) , # % default character
The symbol "," was substituted for "EXP_PBIT_ID" to continue.
185/1 PLS-00103: Encountered the symbol "END" when expecting one of the
following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
LINE/COL ERROR
-------- -------------------------------------------------------------
SQL> Disconnected from Oracle Database 11g Enterprise Edition
:clist afterwards shows the errors have been caught, but not the filename:
:clist
19:21 col 7 error: PLS-00103: Encountered the symbol "EXP_PBIT_ID" when expecting one of the following: := . ) , # % default character The symbol "," was substituted for "EXP_PBIT_ID" to continue.
21:185 col 1 error: PLS-00103: Encountered the symbol "END" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table long double ref char time timestamp interval date binary national character nchar
Does anyone know how I can make this pick up the filename?
Thanks
Dave Smylie
The syntax you're using looks OK to me. So all I have to offer is thoughts...
Even though the file names are not displayed, can you still jump to the correct line in the quickfix window?
Does the compiler produce any output before the file name? Tried a %E before the %+P?
Even though it's not the error format you are looking for, have you tried the oracle.vim plugin?
Knowing NOTHING about efm or vim or this parsing you are trying to do, I would say that you might have better luck performing a query to get the error information. Check out the view
user_errors to gather the error information. It should be easier to get the data the way you want using this method.

Resources