typeFromString Action throws exception-uima ruta - uima

The below code throws the error: Action "typeFromString" is not defined.
CW{-> typeFromString("Person")};
From the documentation, I understand that 'Person' is the name of an annotation that need not be declared already using DECLARE statement and that all CW's will be marked as 'Person'. Please correct me if I'm wrong and let me know how to resolve the above error.

There are two problems:
The type function typeFromString throws an exception if the type is not defined in the typesystem of the CAS (should be fixed). Short names work if they are unambiguous.
The editor reports a false error for the type function if it is used as an implicit action. This can be avoided by using CW{-> MARK(typeFromString("Person"))};. typeFromString is not an action but a function returing a type.
DISCLAIMER: I am a developer of UIMA Ruta

Related

Dart/Flutter linter rule: the type to index a map should be the key type of map?

For example, I have Map<int, int> m;. Then I can write down m['hello'] without any compile-time error, but of course, cannot find any element at runtime. I hope it will produce an error (or warning) at compile-time or lint time.
This is a big problem in many cases. For example, when I refactor Map<A, int> m into Map<B, int> m, I want to have compile-time errors for all accesses like m[some_var_of_type_A], instead of no compile-time errors and suddenly it explodes at runtime. As another example, the de-serialized JSON is of type Map<String, ...> but the key is actually a int. So it is tempting to do var userId=42; deserializedJson[userId] but only to find errors. Actually need to do deserializedJson[userId.toString()].
You know, dart's type system is so strong (even null safe!), and I really enjoy it since it catchs a LOT of bugs at compile-time. So I hope this problem can also be addressed at compile-time.
Thanks for any suggestions!
There currently is no lint to warn about doing lookups on a Map with arguments of the wrong type. This has been requested in https://github.com/dart-lang/linter/issues/1307.
Also see https://github.com/dart-lang/sdk/issues/37392, which requests a type-checked alternative to Map.operator []. In the meantime, Dart's extension mechanism allows anyone to easily add such an alternative themselves. For example, package:basics provides a type-checked Map.get extension.
NOTE:
The original answer was wrong and has been edited to:
point out the right/better answer
explain why the original answer was wrong
Thank you #jamesdlin for pointing this out.
Better answer
As pointed by #jamesdlin in his answer, the lint rule mentioned in the question has been requested in the flutter Github issues, and not in production yet.
Original Answer (wrong but kind of related to the question)
Why it is wrong:
The question was asking about the lint rule when using an index of Map. The answer however gave the lint rule about initializing a map using the wrong index (By the wrong index, I mean different data type).
Below is the answer:
There is a lint rule for this.
For example, if you define a Map like this ->
final Map<String, String> m = {
1: 'some random value',
};
It shows an error right away and this won't compile. This is the error ->
Error: A value of type 'int' can't be assigned to a variable of type 'String'.
1: 'error because index is of type String but assigned value is of type int',
^
Error: Compilation failed.
See the official docs where this lint rule, map_key_type_not_assignable is defined.
I have tested this in dartpad and vs code. Both IDEs show this error.
There could be some issues in your IDE configuration if you're not seeing this lint error.
As for your question, there is already a lint rule for this as explained above.

Get parameter name in Clion plugin

I am developing a plugin for Clion (C++) that needs to access caller parameter name, e.g. if a function is declared:
void fun(int a);
and called
fun(42);
when the intent is invoked on 42 PsiElement it should get the corresponding parameter name, "a" in this case.
In a similar plugin for Intellij (Java), I get the parameter name with PsiCallExpression.resolveMethod() which contains the list of parameters. However, I cannot figure out how to do this in a Clion plugin. I can get a reference of a corresponding OCCallExpression, but it does not seem to contain a reference to the declared function. I tried to play around with ReferencesSearch.search(), but it did not find the declaration of the function.
At the same time, the IDE itself displays all the parameter name hints:
so I suppose it must be possible.
How can I get the parameter name for a given caller argument expression?
Please, look at InlayParameterHintsExtension.forLanguage(OCLanguage.getInstance()) and InlayParameterHintsProvider.getParameterHints

Is there a way in Dart to mark a function as throwing an exception?

I was trying to find a way in Flutter/Dart to mark a function that may throw an exception during its execution. After some time searching in the documentation and Google I did not find any way of doing this.
In other language, for example Swift, Java, Kotlin, etc I know we have such mechanism.
Sample code in Swift is:
func doSomething() throws { ... }
Does anyone know if this exists in Dart?
I think it will be useful.
If it does not exist due to Dart language desing then maybe anyone can explain the reason behind this decision.
Thanks in advance!
There is no way in Dart to mark a function as potentially throwing.
All functions should be assumed to potentially throw (if for no other reason, then because of an out-of-memory or stack-overflow situation).
If you look at Swift, the throws is about exceptions, not errors. Dart does not distinguish the two, you can throw anything. Swift has put itself in a place between Java ("have to declare all thrown exceptions") and Dart or C# ("Can't declare exceptions").
Marking a function as "throwing" doesn't help the compiler in any way because it has to assume that all other functions might too. The Swift approach is there to ensure that distinctively marked exceptions are not ignored. Unless you want to, then you can try! them and turn the exception into an error.
If a function does throw as part of normal usage, you should document it in the function's documentation.
Dart also have the issue of function types. Is a function from int to int the same type as another function from int to int if the latter can throw? Separating function types into throwing and non-throwing get complicated quickly. Even more so if you want to specify what it throws. It's not impossible, but it's one more complication.
The one thing that you will get with the Dart null safety update (currently being worked on), is a way to state that a function always throws. If you make the return type Never in null-safe code, then the type system will prevent you from returning any value, and since a function call must end by either returning a value or throwing, a call to a function with return type Never can only end by throwing.

Static Code Analyzer to enforce Type Annotation in Scala

Is there any static code analyzer that can be used to enforce Type Annotation in Scala. For example, when a developer writes a statement without type annotation as show in the example below, he should get a compile time error
val name="sometime" //This should throw compile time error
This is what I expect the developer to write,
val name: String = "somename" // Type annotation 'String' explicitly specified
I am able to enforce few good practices using Scalastyle plugin in sbt(which throws compile time error when any of the rules specified for ScalastylePlugin is not followed). But I could find any rule that enforce type annotation
PS : Scalastyle does provide provision to create CustomRules(by extending the class ScalariformChecker). But I am just looking for a way to avoid developing custom code

Decision Table can't do normal convertions. Not automatically converting int/double to BigDecimal

I'm trying to upload a Decision Table via workbench (6.2.0) but it fails validation because:
Rule Compilation error The method setCost(BigDecimal) in the type MyType is not applicable for the arguments (double)
It seems that normally you can solve this by adding dialect "mvel" to the rule. But I can't find a way to do this with a spreadsheet (.xls). Can anyone please help?
I'm hoping for a better solution than writing an overload for setCost on the POJO!
You can define all rule attributes outside rules as well. An attribute remains valid until countermanded by another attribute value.
This means that you can use the spreadsheet's feature for defining a function to specify the dialect.
To clarify, this means that you can just write:
-----------------------
|RuleSet | package
-----------------------
|Functions | dialect "mvel"
...
and voila.