No viable alternative at input 'type' with Grakn - vaticle-typedb

In my Grakn schema, I am inserting this:
device sub entity,
has type,
plays active-device;
However, when I try to insert this, I get this error:
graql.lang.exception.GraqlException: syntax error at line 72:
has type,
^
no viable alternative at input 'type'
syntax error at line 72:
has type,
^
mismatched input 'type' expecting {'match', 'define', 'undefine', 'insert', 'compute'}
at graql.lang.exception.GraqlException.create(GraqlException.java:54)
at graql.lang.parser.Parser.parseQuery(Parser.java:114)
at graql.lang.parser.Parser.parseQueryListEOF(Parser.java:127)
at graql.lang.Graql.parseList(Graql.java:64)
at grakn.console.ConsoleSession.executeQuery(ConsoleSession.java:206)
at grakn.console.ConsoleSession.load(ConsoleSession.java:132)
at grakn.console.GraknConsole.run(GraknConsole.java:103)
at grakn.console.GraknConsole.main(GraknConsole.java:139)
I don't think I have any syntax errors, why is this throwing an error?

type is a reserved keyword in Grakn. When person is defined, and you call match $x type person; get;, a single result is returned: the concept type with label person.
Try naming your attribute device-type instead.

Related

C# CS1503 Select cannot infer type, mixed up by System.Func and Func

I am using Select() on a collection to create many transform functions. C# is complaining the Select call cannot infer the type, apparently it is expecting a System.Func<> but is getting a Func<>...? I don't see the difference. The exact error text:
Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<Func<Foo, Foo>>' to 'System.Collections.Generic.IEnumerable<System.Func<Foo, Foo>>' [language-core]csharp(CS1503)
The code, paraphrased a bit, looks like (ExtendBy returns a Foo):
BarCollection.Select(b => ((Foo f) => f.ExtendedBy(b)))
If I specify the types related to the Select explicitly it works, but that's a hassle:
BarCollection.Select<Bar, System.Func<Foo, Foo>>(b => ((Foo f) => f.ExtendedBy(b)))
If I specify the types but use Func instead of System.Func, I get the original error as when the type is not specified:
BarCollection.Select<Bar, Func<Foo, Foo>>(b => ((Foo f) => f.ExtendedBy(b)))
So it seems like some other Func besides System.Func is getting used and confusing things. Is there a way to fix this so Select can determine the type implicitly? Both pieces of code are in the same library project, with TargetFramework set to net5.0.
For reference, here are my using statements for the file calling Select():
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

Error: The operator '+' isn't defined for the class 'Object'

As a complete Dart beginner coming from python and javascript, I find this behavior quite strange:
var user = {'name': 'John Doe', 'birth_y': 1980};
2021-user['birth_y'] // is 41
But if the operator is on the right.
user['birth_y'] + 41 // error
The error:
Error: The operator '+' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '+' operator.
user['birth_y'] + 41;
^
From the error, one guesses that for maps with mixed types, entries have type 'Object', Yet:
user['birth_y'] is int // true
user['birth_y'].runtimeType // int
This behavior is also exhibited by lists of mixed types,
What am I missing?
Dart does a statically analysis of your program before running it. In this analyze phase, it will look at the data type of your variables and see if it is statically safe.
In your case you have this Map:
var user = {'name': 'John Doe', 'birth_y': 1980};
Since your Map contains different types of values, Dart will try to see which data type can be used for all your values. In this case, the only thing String and int shares is the Object type. So user is being analyzed to be of the type Map<String, Object>.
This means that when you get a object from user, the only thing the analyzer can be sure about is it is of the type Object.
So when you do:
user['birth_y'] + 41
The analyzer will assume you get a Object which does not have the + operator.
You should in general not use Map as some kind of object which contains different data types. Instead create a class which makes it possible to write type safe code.

Cannot call `JSON.parse` with `localStorage.getItem(...)`

Just added Flow types to a project I'm working on and progressively adding types until I got to this error:
Cannot call JSON.parse with localStorage.getItem(...) bound to text because null or undefined [1] is incompatible with
string [2]
This comes from a expression:
const myVar = JSON.parse(localStorage.getItem('itemName'))
I understand why I get this error (except maybe the "bound to text" part), but couldn't find a way around it. I'd appreciate any help here!
So, the function localStorage.getItem can return null values and flow wants you to tackle them before parsing it. As JSON.parse only takes a string, you can do the following:
localStorage.getItem("key") || '{}'
So, if it returns null. The empty object string is chosen, which JSON.parse can parse into an empty object.
Prefer using 'null' than '{}' as it parses to empty object
JSON.parse(localStorage.getItem("key") || 'null') // null
JSON.parse(localStorage.getItem("key") || '{}') // {} - empty object

Creating dictionary of functions with symbols as keys

I am trying to create a dictionary of functions with symbols as keys but I am getting an error. I have tried the following:
functions = Dict{
:gauss => (v::Float64)->gauss(v, 0.0, 1.0),
:sin => (v::Float64)-> sin(v),
:nsin => (v::Float64)->(-sin(v)),
:cos => (v::Float64)-> cos(v),
:ncos => (v::Float64)->(-cos(v)),
:tanh => (v::Float64)->tanh(v),
:sigm => (v::Float64)->sigmoid(v),
:id => (v::Float64)->id(v)
}
The error I am getting :
ERROR: LoadError: TypeError: in Type, in parameter, expected Type, got Pair{Symbol,getfield(Main, Symbol("##105#113"))}
Please let me know what I am doing wrong. Thanks for the help in advance.
I figured the{} need to replaced by ().
As you found out your yourself, the {} brackets indicate type parameters whereas the paranthesis indicate a constructor call.
Note, that the ::Float64 type annotations aren't necessary for your functions to be performant. Think of them more as a user interface restriction; that is users won't be able to call your methods with non-Float64s. However, if you want to specify types explicitly, you could also specify the type of your dictionary explicitly as such Dict{Symbol, Function}(...). However, since you don't initialize the Dict empty, Julia will figure out the best type based on your input (symbol function pairs).

How to implement generic Max<TSource>(Func<TSource,TSource> func)

I am busy writing my own collection type and need to have a function
Max that returns the value in the collection, where one of the value attributes is a max or some condition holds.
So I am trying to call Max(Func<...) on one of the underlying .net collections, but
I can't seem to get it to work:
public TValue MaxValue(Func<TValue,TValue> func)
{
return this.valueSet.Max<TValue>(func);
}
but I am getting 2 errors:
Argument 2: cannot convert from 'System.Func<TValue,TValue>' to System.Func<TValue,int>'
and
'System.Collections.Generic.SortedSet<TValue>' does not contain a definition for 'Max'
and the best extension method overload 'System.Linq.Enumerable.Max<TSource>(System.Collections.Generic.IEnumerable<TSource>,
System.Func<TSource,int>)' has some invalid arguments
I just can't seem to figure out what I should be doing here...
When you call:
this.valueSet.Max<TValue>(func);
the compiler interprets this as one of the Max overloads with one generic type. Either explicitly point out that the return value also should be a TValue type:
this.valueSet.Max<TValue, TValue>(func);
or use implicit typing and let the compiler sort out the types itself:
this.valueSet.Max(func);

Resources