Double typed literal in Apache Jena - jena

I want to create an object in a triple with a datatype Double. I have the following code:
if(!spine.equals(null)){
register_res.addProperty(spineWidth, model.createTypedLiteral(new XSDDouble(spine)));
}
I am reading spine from a csv file and saving it in a String.
I am getting the following error:
java.lang.NullPointerException
at org.apache.jena.datatypes.xsd.XSDDatatype.<init>(XSDDatatype.java:231)
at org.apache.jena.datatypes.xsd.impl.XSDDouble.<init>(XSDDouble.java:38)
at VolumesUpload.main(VolumesUpload.java:140)
Any idea what is wrong please?

XSDDouble is the class of the datatype, not the value.
You want:
model.createTypedLiteral("4.5", XSDDatatype.XSDdouble);
if spine is the lexical form of the value or
model.createTypedLiteral(Double.valueOf("4.5"));
to create from a value.

Related

Microsoft Graph: Unable to filter by binary singleValueExtendedProperty

I'm trying to retrieve an event from the grapi api based on a binary extended property that I already have a value for. I have retrieved this value from the same api so I know that an event with this value exists. I also know that the property id is correct since I used this with .Expand() to get the value.
var value = "BAAAAIIA4AB0xbcQGoLgCAAAAAAwMvfBFvzUAQAAAAAAAAAAEAAAAEZ53uCfQ51AhtRf+FNQjOk=";
var cleanGlobalObjectIdPropertyId = "Binary {6ed8da90-450b-101b-98da-00aa003f1305} Id 0x23";
var events = await client.Users["myuser#example.com"].Events.Request()
.Filter($"singleValueExtendedProperties/Any(ep: ep/id eq '{cleanGlobalObjectIdPropertyId}' and ep/value eq '{value}')")
.GetAsync();
This is the error i get:
Microsoft.Graph.ServiceException : Code: ErrorInvalidUrlQueryFilter
Message: The filter expression for $filter does not match to a single extended property and a value restriction.
I have used the same filter syntax with an extended property of type string and that works fine, so I think the fact that this is a binary property is relevant to the problem.
I also faced to this problem. But I try to search for /messages against mapi property SearchKey.
I was thinking to use something like:
https://graph.microsoft.com/v1.0/me/messages?$filter=singleValueExtendedProperties%2FAny(ep%3A%20ep%2Fid%20eq%20'Binary%200x300B'%20and%20ep%2Fvalue%20eq%20'yxum+DwfxUy13C4qs5R6ig==')
According to https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752358
"The six comparison operators can be used with all primitive values except Edm.Binary, Edm.Stream, and the Edm.Geo types."
So I assume that binary should be casted or decoded from base64 somehow, or it's impossible at all.
UPDATE:
So I finally figure it out.
Let's say I got the value of singleValueExtendedProperty as:
{
"id": "Binary 0x300b",
"value": "yxum+DwfxUy13C4qs5R6ig=="
}
And I wanted to find message by value of this property. The problem here is that '+' should be encoded if exists. Also value should be casted to Edm.Binary. Correct query looks like this:
https://graph.microsoft.com/v1.0/me/messages?$filter=singleValueExtendedProperties%2FAny(ep%3A%20ep%2Fid%20eq%20'Binary%200x300B'%20and%20cast(%20ep%2Fvalue,Edm.Binary)%20eq%20binary'yxum%2BDwfxUy13C4qs5R6ig==')

Numeric sort in Manual (Legacy) index in Neo4j 3 is not working correctly

I'm using Legacy indexing (now called Manual indexing). After migration from Neo4j 2 to version 3 I have some problems with numeric sorting.
Example of correct statement in Neo4j 2:
queryContext.sort(new Sort(new SortField(AGE, SortField.INT, false)));
This stament should be changed for Neo4j 3 (Lucene 5):
queryContext.sort(new Sort(new SortField(AGE, SortField.Type.INT, false)));
But if you use this sort statement you will get an exception:
java.lang.IllegalStateException: unexpected docvalues type SORTED_SET for field 'firstName' (expected=SORTED). Use UninvertingReader or index with docvalues.
at org.apache.lucene.index.DocValues.checkField(DocValues.java:208)
at org.apache.lucene.index.DocValues.getSorted(DocValues.java:264)
at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getSortedDocValues(FieldComparator.java:762)
at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getLeafComparator(FieldComparator.java:767)
at org.apache.lucene.search.FieldValueHitQueue.getComparators(FieldValueHitQueue.java:183)
at org.apache.lucene.search.TopFieldCollector$SimpleFieldCollector.getLeafCollector(TopFieldCollector.java:164)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.replayTo(DocValuesCollector.java:297)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.getTopDocs(DocValuesCollector.java:275)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.getIndexHits(DocValuesCollector.java:150)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.search(LuceneLegacyIndex.java:346)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:261)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:205)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:217)
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeLegacyIndexQuery(StateHandlingStatementOperations.java:1440)
at org.neo4j.kernel.impl.api.OperationsFacade.nodeLegacyIndexQuery(OperationsFacade.java:1162)
at org.neo4j.kernel.impl.coreapi.LegacyIndexProxy$Type$1.query(LegacyIndexProxy.java:83)
at org.neo4j.kernel.impl.coreapi.LegacyIndexProxy.query(LegacyIndexProxy.java:365)
I think this is caused by new added statement in Neo4j indexer class (Neo4j is indexing field for sorting automatically now?). See in:
org.neo4j.index.impl.lucene.legacy.IndexType CustomType addToDocument( Document document, String key, Object value )
new line:
document.add( instantiateSortField( key, value ) );
and method instantiateSortField is creating SortedSetDocValuesField
So I changed my code to:
queryContext.sort(new Sort(new SortedSetSortField(AGE, false)));
This runs OK but sorting is not working because numbers are sorted as string. I see that "value" parameter is String every time in method "addToDocument". I think the root cause is explained it this old comment:
see comment in class org.neo4j.index.impl.lucene.legacy.IndexType CustomType
// TODO We should honor ValueContext instead of doing value.toString() here.
// if changing it, also change #get to honor ValueContext.
Am I missing some new way how to index, search and sort data in Neo4j 3 or this is really problem that values are indexed as string in Neo4j?
Simple unit test for Neo4j 2 and Neo4j 3 can be downloaded
Solution added by MishaDemianenko at GH issue

Array.size() returned wrong values (Grails)

I'm developing an app using Grails. I want to get length of array.
I got a wrong value. Here is my code,
def Medias = params.medias
println params.medias // I got [37, 40]
println params.medias.size() // I got 7 but it should be 2
What I did wrong ?
Thanks for help.
What is params.medias (where is it being set)?
If Grials is treating it as a string, then using size() will return the length of the string, rather than an array.
Does:
println params.medias.length
also return 7?
You can check what Grails thinks an object is by using the assert keyword.
If it is indeed a string, you can try the following code to convert it into an array:
def mediasArray = Eval.me(params.medias)
println mediasArray.size()
The downside of this is that Eval presents the possibility of unwanted code execution if the params.medias is provided by an end user, or can be maliciously modified outside of your compiled code.
A good snippet on the "evil (or lack thereof) of eval" is here if you're interested (not mine):
https://javascriptweblog.wordpress.com/2010/04/19/how-evil-is-eval/
I think 7 is result of length of the string : "[37,40]"
Seems your media variable is an array not a collection
Try : params.medias.length
Thanks to everyone. I've found my mistake
First of all, I sent an array from client and my params.medias returned null,so I converted it to string but it is a wrong way.
Finally, I sent and array from client as array and in the grails, I got a params by
params."medias[]"
List medias = params.list('medias')
Documentation: http://grails.github.io/grails-doc/latest/guide/single.html#typeConverters

Could not parse sql timestamp string error message

At the point of posting a record to a database table I get the following error:
Could not parse sql timestamp string.
At the click of a button my code does the following:
qry1.Open;
qry1.Insert;
qry1.FieldByName('files_uploaded').asdatetime := qry2.FieldByName('files_uploaded').asdatetime;
qry1.Post;
qry1.Close;
The datatype for the field in the database table is timestamp.
Example of the data in the field : 2014-04-23T14:48:40.816+01:00.
I'm not entirely sure what I'm doing wrong or unless its something to do with the field data.
Any help would be appreciated.
Please try this code:
qry1.Open;
qry1.Insert;
qry1.FieldByName('files_uploaded').AsSQLTimeStamp :=qry2.FieldByName('files_uploaded').AsSQLTimeStamp;
qry1.Post;
qry1.Close;
Try setting ".Value" instead of defining the Data Type. When you use .Value the dataset will convert everything that is necessary.
qry1.Open;
qry1.Insert;
qry1.FieldByName('files_uploaded').Value :=qry2.FieldByName('files_uploaded').Value;
qry1.Post;
qry1.Close;

Delphi & Absolute database : Delete Query

Why is it that my query does not work ?
Form1.ABSQuery1.Close;
Form1.ABSQuery1.SQL.Clear;
Form1.ABSQuery1.SQL.Text:='DELETE FROM LOG WHERE status = ''YES'' and DATE BETWEEN :d1 and :d2';
Form1.ABSQuery1.Params.ParamByName('d1').Value :=cxDateEdit1.Date;
Form1.ABSQuery1.Params.ParamByName('d2').Value :=cxDateEdit2.Date;
Form1.ABSQuery1.ExecSQL;
Form1.ABSTable1.Refresh;
I get this error :
You should be using AsDateTime in your Params setting code.
Form1.ABSQuery1.SQL.Text:='DELETE FROM LOG WHERE status = ''YES'' and DATE BETWEEN :d1 and :d2';
Form1.ABSQuery1.Params.ParamByName('d1').AsDateTime :=cxDateEdit1.Date;
Form1.ABSQuery1.Params.ParamByName('d2').AsDateTime :=cxDateEdit2.Date;
Form1.ABSQuery1.ExecSQL;
Using Value converts the cxDateEdit1.Date to a generic string format for assignment, and that doesn't properly convert it to the YYYY-MM-DD format that most databases (including ABS) expect. Properly using AsDateTime allows the database driver/component to convert to the specific date format the DBMS uses.
Also, is your database field really named DATE? Date is usually a reserved word or function name in most DBMS, and if it is it usually needs to be quoted.
Form1.ABSQuery1.Params.ParamByName('d1').DataType := ftDateTime;
Form1.ABSQuery1.Params.ParamByName('d1').Value :=cxDateEdit1.Date;
You must explicitly specify the data type of the parameter to it had no such problem, and then convert to a string does not need to

Resources