jess multislot value matching ignoring the order - jess

I am trying to check if there already exists the same instance or not.
(defemplate justificand (slot consq) (multislot antes))
(assert (justificand (consq s) (antes p q r))) ;;; order p q r
(defrule test
(exists (justificand (consq s) (antes q p r))) ;;; order q p r
=>
(printout t "matching success " crlf))
In my case, I assert a justificand with (antes p q r) but the order of p, q and r
is not important. So, test rule need to succeed even if it test with (antes q p r).
But, jess seems to consider order of multislot values for matching.
Any method to ignore the order of multislot values for matching?
Thanks

With your deftemplate and this function
(deffunction unleq (?l1 $?l2)
(and (eq (length$ ?l1)(length$ $?l2))
(eq (length$ ?l1)(length$ (intersection$ ?l1 $?l2)))))
and inserting facts:
(deffacts f1
(justificand (consq s1) (antes p q r))
(justificand (consq s2) (antes r p q))
(justificand (consq s3) (antes p q x))
(justificand (consq s4) (antes p q))
(justificand (consq s4) (antes r q q p p)))
this rule fires:
(defrule match
(justificand (consq ?s) (antes $?pqr&:(unleq $?pqr p q r)))
=>
(printout t "match for " ?s crlf))
giving
match for s2
match for s1

Related

Haskell - Passing a function as an argument

so in haskell I have the following 2 functions made (they are just performing some math operations)
cubicQ :: Float -> Float -> Float -> Float
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR :: Float -> Float -> Float -> Float -> Float
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
I am to make a third function cubicS that has a requirement that the function be of type Float -> Float -> Float and it calculates its output from q and r, which is the output for cubicQ and cubicR. How would I pass the functions cubicQ and cubicR as arguments q and r in cubicS? Below is what I have tried so far but I am stumped. Any help would be greatly appreciated.
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
where q = (cubicQ a b c d)
r = (cubicR a b c)
try this:
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
f a b c d = cubicS (cubicQ a b c) (cubicR a b c d)
main = do print $ f 1 2 3 4
or:
cubicS a b c d = (r+ (q**3+r**2)**(1/2))**(1/3)
where q = cubicQ a b c
r = cubicR a b c d
or:
cubicS a b c d =
let q = cubicQ a b c
r = cubicR a b c d
in (r+ (q**3+r**2)**(1/2))**(1/3)
see:
cubicQ :: Float -> Float -> Float -> Float
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR :: Float -> Float -> Float -> Float -> Float
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS :: Float -> Float -> Float -> Float -> Float
cubicS a b c d =
let q = cubicQ a b c
r = cubicR a b c d
in
(r+ (q**3+r**2)**(1/2))**(1/3)
main = do print $ cubicS 1.1 2.2 3.3 4.4
output:
9.736999e-2
and if you restricted to cubicS being cubicS: Float -> Float -> Float:
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
cureS a b c d = cubicS q r
where q = cubicQ a b c
r = cubicR a b c d
main = do print $ cureS 1.1 2.2 3.3 4.4

How can I do matching on a field containing text that alternates with spaces?

I have an Elasticsearch v2.4.1 index in which I store values from a JSON feed. Sometimes I get values separated by spaces in some fields, like:
"titulo" : "E l a ñ o q u e e l m e r c a d o d e j ó d e a s u s t a r"
This happens around 15% of the time and prevents queries such as:
localhost:9200/indice/_search?q=titulo:mercado
To match the document above.
I think the problem could be solved by using some sort of CharFilter, I thought of the N-gram filter but that does the opposite. I know this might be complex since ES should, at some level, infer the language (or maybe I could specify it); deal with ambiguities and so on...
Another examples of the same:
"title" : "El g a l a r d ó n se e n t r e g a r á el p r ó x i m o día 2 4"
"title" : "G a m a a c t u a l i z a d a d e b o m b a s d e calor A q u a t e r m i c"
"title" : "K a s p e r s k y : m á s q u e a n t i v i r u s"

Subquery error in mysql

SELECT
c.cy_id AS cy_id,
(SELECT
c.to_id
FROM c
WHERE (c.to_id = se.ar))AS tsn,
(SELECT
se.x
FROM se
WHERE (c.to_id = se.ar)) AS X,
(SELECT
se.y
FROM se
WHERE (c.to_id = se.ar)) AS y
FROM (c
JOIN se)
WHERE (c.to_id = se.ar)
This above query when i execute in mysql gives error subquery returns more than one row.
But when i do the below query it returns the result.
SELECT
c.cy_id AS cy_id,
(SELECT DISTINCT
c.to_id
FROM c
WHERE (c.to_id = se.ar))AS tsn,
(SELECT
se.x
FROM se
WHERE (c.to_id = se.ar)) AS X,
(SELECT
se.y
FROM se
WHERE (c.to_id = se.ar)) AS y
FROM (c
JOIN se)
WHERE (c.to_id = se.ar).
I need an reason for this.
It appears your c table has multiple rows, but they all have the same to_id value. If multiple records are returned by a subquery, you'll get an error.
Also, your query doesn't appear to require any subqueries. Try this and see if it gets you the results you want:
SELECT
c.cy_id,
c.to_id AS tsn,
se.x AS X,
se.y AS y
FROM c
JOIN se
ON c.to_id = se.ar

Receiving data with spaces, thru sockets

I'm using C++ with QT4 for this. And when I try to send large html files(in this case, 8kb), the process of sending and receiving work well. But the file received come with spaces between each character of the html file. Here an example, the file is sent like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">a</p></body></html>
and it's received, like this:
¼ < ! D O C T Y P E H T M L P U B L I C " - / / W 3 C / / D T D H T M L 4 . 0 / / E N " " h t t p : / / w w w . w 3 . o r g / T R / R E C - h t m l 4 0 / s t r i c t . d t d " >
< h t m l > < h e a d > < m e t a n a m e = " q r i c h t e x t " c o n t e n t = " 1 " / > < s t y l e t y p e = " t e x t / c s s " >
p , l i { w h i t e - s p a c e : p r e - w r a p ; }
< / s t y l e > < / h e a d > < b o d y s t y l e = " f o n t - f a m i l y : ' M S S h e l l D l g 2 ' ; f o n t - s i z e : 8 . 2 5 p t ; f o n t - w e i g h t : 4 0 0 ; f o n t - s t y l e : n o r m a l ; " >
< p s t y l e = " - q t - p a r a g r a p h - t y p e : e m p t y ; m a r g i n - t o p : 0 p x ; m a r g i n - b o t t o m : 0 p x ; m a r g i n - l e f t : 0 p x ; m a r g i n - r i g h t : 0 p x ; - q t - b l o c k - i n d e n t : 0 ; t e x t - i n d e n t : 0 p x ; " > < / p > < / b o d y > < / h t m l >
the code i'm using for sending and receiving:
Sending code:
qDebug() << "Connected. Sending file to the server"; QString text = ui->QuestHtmlText->toPlainText();
if(text.length() < 1024)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint16(0) << QUESTION_HTML;
out << text;
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
qDebug() << "Block size: " << block.size();
socket.write(block);
return;
}
for(int i = 0; i < text.length(); i+=1024)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint16(0) << QUESTION_HTML;
if((text.length() - i) > 1024)
out << text.mid(i, i+1024);
else
out << text.right(1024 - i);
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
qDebug() << "Block size: " << block.size();
socket.write(block);
}
Receiving code:
qDebug() << "Writing File";
QDataStream in(this);
QString temp = "Teste.html", text;
QFile myFile(".//Questions//" + temp);
myFile.open(QIODevice::WriteOnly);
QDataStream out(&myFile);
while(!in.atEnd())
{
in >> text;
out << text;
}
I did opened a post before, here: Sending data through socket spaces, receiving with spaces
People stopped helping me out. By the way, i didnt feel like my question was completly answered. So I opened another post.
I also looked in the FAQ section to see what should I do in this case. But with no sucess.
Anyway, my question now is: should I remove the quint16? what should I use to determine the size of the incoming packet then ?
Thanks, and I'm sorry about the mistakes I may have made.
The stuff you are getting back in the file is not your original text, but QString serialization form, which is unsuprisingly UTF-16. If you want your text back, read the input QDataStream back to QString and save that into file.
While prefixing your data with a length is generally a good idea, it is absolutely redundant with QString >> QDataStream. Read up something here or here. Moreover you have developed a mind boggingly obfuscated way which i suspect is doing nothing. QByteArray is not implementing QIODevice (indeed, why it should) so your out.device()->seek() is a base virtual implementation, empty and just returning true. I won't be surprised if your length "header" is found at the end of your serialization dump file.
Edit: i think that your html transport might start working correctly only by leaving out the confused quint operation completely and use out QTextStream instead of QByteStream.
I posted the solution for my case in the other post.
Thanks you all for the attention

What is this type of table called?

SELECT
*
FROM
(
SELECT a, b, c
FROM ABC
WHERE f = '1'
LEFT JOIN
SELECT v, n, m
FROM VBN
WHERE g = '1'
ON (v = a)
);
I am trying to select from a table is is built on the fly from conditions, what is this kind of table called? Live table?
You can call it as subquery.
If you wanted to apply a name to this subquery you can use an alias or by creating a view.
SELECT
aJoinedTable.*
FROM
(
SELECT a, b, c
FROM ABC
WHERE f = '1'
LEFT JOIN
SELECT v, n, m
FROM VBN
WHERE g = '1'
ON (v = a)
) as aJoinedTable;