Stanford CoreNLP Morphology.stemStatic disable lowercase conversion? - stanford-nlp

The comments on the stemStatic method of the Morphology class state that it will:
return a new WordTag which has the lemma as the value of word().
The default is to lowercase non-proper-nouns, unless options have
been set.
(https://github.com/evandrix/stanford-corenlp/blob/master/src/edu/stanford/nlp/process/Morphology.java)
How/where can I set those options, to disable the lowercase conversion?
I've looked through the source but can't see how I can set options that will affect this static method. Frustratingly, the related static lemmatise method -- lemmaStatic -- includes a boolean parameter to do exactly this...
I'm using v3.3.1 via Maven...
thanks!

Ok after looking at this for a bit, it seems the right track might be to not use the static method, but instead build a Morphology instance with:
public Morphology(Reader in, int flags) {
The int flags will set the lexer.options.
Here are the lexer options (from Morpha.java) :
/** If this option is set, print the word affix after a + character */
private final static int print_affixes = 0;
/** If this option is set, lowercase all tokens */
private final static int change_case = 1;
/** Return the tags on the input words if present?? */
private final static int tag_output= 2;
The int flags is the bit string for the 3 options, so 7 = 111 , meaning all options will be set to true , 0 = 000 , all options false, 5 = 101 would set print_affixes and tag_output, etc...
Then you can use apply in Morphology.java
public Object apply(Object in) {
Object in should be a WordTag built with the original word and tag.
Please let me know if you need any further assistance!
We could also change Morphology.java to have the kind of method you want! The above is if you don't want to play around with customizing Stanford CoreNLP.

Related

How to change string to integer

How can I change a string input to integer-
for example-
read_line_to_codes(user_input,L),
atom_codes(C,L).
In this C is storing a string.Suppose the user entered 18.So I want to use this 18 as an integer so that I can use operations like >= with C.Is this possible in Prolog?
Prolog datatypes don't include 'strings'. SWI-prolog added it recently, but you can stay on ISO safety lane with number_codes
You can forcefully assigned an int datatype to the user input, you are letting the JVM know that you know what you are doing and this will let the program compile in case if the int data type is smaller than the user input string size. Here is an example code to help you.
public class stringToInt{
public static void main(String []args){
string C = 18; //User input, make sure to use the scanner class to get the user input value
int int_C = (int) C;
/**Your new value is now in int datatype and you can go ahead and use int_C for your arithmetic
opreation **/
}
}

Accessing public static final field using JoSQL

I've been using JoSQL for quite a few months now and today I came across a problem I am not sure how to solve. I probably could solve it by binding variables/placeholders, but I'd like to include the fields in the query.
SELECT * FROM ...MyObject WHERE getType != com.mypackage.myclass.TYPE_A
This is the query that I have. TYPE_A is a public static final int attribute in "myclass" class. Accessing methods (such as getType) is easy, because getType is expected to be a method from MyObject - just that I do not write round brackets after it (this is how JoSQL works as far as I know).
Does anyone happen to have an idea how to access a public static final field?
JoSQL uses gentlyweb-utils; it seems to be some sort of Accessor/Getter/Setter framework. I'd love to access that attribute without having to bind variables, but I haven't been able to do so.
Thanks for your help in advance! I really appreciate it.
I think I have figured something out. First: it seems not possible to access the static variables for whatever reason. I've used the following approach to solve my issue:
create a method, which picks up a given JoSQL-statement
mark the constants, which you want to replace, by say "{?FULL_PACKAGE_AND$CONSTANT}"
use reflections to determine the column as well as the column (and value) from the field
iteratively replace the statement until no "{?"-values are available
Example:
JoSQL-statement looks like this:
(isWeapon = TRUE AND getItem.getType2 = {?com.l2jserver.gameserver.model.items.L2Item$TYPE2_WEAPON})
Method using the query-object:
final Query query = DataLayer.createJoSqlQuery(joSql);
Method (pre)processing the JoSQL-statement:
final Query query = new Query();
int variableColumn = 0;
while (joSql.indexOf("{?") > -1) {
variableColumn++;
final int startIndex = joSql.indexOf("{?");
final int endIndex = joSql.indexOf("}", startIndex);
final String value = joSql.substring(startIndex + 2, endIndex);
try {
final Object variableValue = Class.forName(value.split("\\$")[0]).getField(value.split("\\$")[1]).get(null);
query.setVariable(variableColumn, variableValue);
joSql = joSql.replace("{?" + value + "}", "?");
}
catch (...) {
e.printStackTrace();
}
}
query.parse(joSql);
return query;
The JoSQL-statement preprocessing method bascially iterates through a given JoSQL-statement and sees whether it contains the string "{?". If it does, it does some copy and paste (note the dollar-symbol right in front of the constant name).
Finally it creates the objects and sets them using something similar to prepared statements "setObject"-method. In the end it just replaces the values within the JoSQL-statement with question marks ("?") and sets a corresponding object in the newly created Query-object, which is later used to retrieve information.

KeyTyped key not showing key

I am trying to convert from processing to processingjs and have something I just can't understand.
In processing the following code returns whichever letter you type in, though in processingjs it just comes back with the keycode value but I need the letter not the code.
String name="";
void setup(){
size(200,200);
}
void draw(){
}
void keyPressed() {
if(key==ENTER) {
name="";
}
else {
name+=key;
println(name);
}
}
After hours of searching and the above answer I've found the answer here peepproject.com/forums/thread/266/view more eloquently than I. Basically the solution is to convert the int to a char() before constructing a String and putting it into an array.
Instead of name += key, try name += key.toString().
Processing's println automatically does type conversion for you, so the char value of PApplet.key gets printed as a letter. JavaScript string concatenation works differently; the integer value of PApplet.key will be appended to the string as an integer and will not automatically be converted to a string. You have to do it manually.
You need to use the char conversion function in Processing and Processing.js:
http://processingjs.org/reference/char_/
The reason why it's displaying as a number is this line:
char x = 97; //supposed to be an 'a'
Does a cast in Java (may require char x = (char)97).
However in processing.js it is executed as:
var x = 97;
Since javascript has dynamic typing. You therefore need to explicitly force type casts such as from int->char.

Boolean that can only be flipped to true

Is there a name for a data structure (read: boolean) that can only be moved from false to true, and not back to false? Imagine something encapsulated like so:
private var _value = false
def value = _value
def turnOnValue() = value = true
And out of curiosity, are there any platforms that support it natively? This seems like something somebody must have come across before...
You're describing a temporal property of a variable; rather than a data structure as such. The data type is a simple boolean, but it is how it is used that is interesting -- as a sort of 'latch' in time.
That kind of latch property on a boolean data type would make it an example of a linearly typed boolean. Linear types, and other kinds of uniqueness types are used to enforce temporal properties of variables -- e.g. that they can only be used once; or cannot be shared.
They're useful for enforcing at compile time that an action has happened (e.g. initialization) or having a compile-time proof that an object is not shared. Thus, they're most common in systems programming, where proofs of low level properties of this are key to correct software design.
In perl you have Tie Variables and you can build your on scalar value and make this kind of "type". But natively... maybe in Smalltalk can be possible to build something like this, or Prolog, but I don't know.
Make your own data type
public final class CustomBoolean {
private boolean value;
public void setValue(boolean value){
// Bitwise OR
this.value |= value;
}
public boolean getValue(){
return value;
}
}
Example ::
public static void main (String[] args)
{
CustomBoolean foo = new CustomBoolean();
foo.setValue(false);
System.out.println(foo.getValue());
foo.setValue(true);
System.out.println(foo.getValue());
foo.setValue(false);
System.out.println(foo.getValue());
}
The output would be ::
false
true
true
This means you'll have to call getValue() before doing any explicit boolean operations
ie
if(foo.getValue() && 1 == 1)
The example is written in Java.

How can I add an alias to Ruby 1.9's Enocding.aliases?

Wanted to add an alias for one of the charsets that PayPal may use for its IPN (Instant Payment Notification).
This is silently ignored:
Encoding.aliases["x-mac-greek"] = "macGreek"
This doesn't work, either:
Encoding.aliases.update("x-mac-greek" => "macGreek")
Any other suggestions?
I don't think this is possible. If you look at the source for the aliases method you can see that it creates a new hash each time it's called, with the aliases copied into from the internal representation.
From what I can see it doesn't look like there's any way to modify this internal data from a Ruby program.
Perhaps you just need to check the string you get from PayPal before trying to use it as an encoding.
A following C extension will work:
#include <ruby.h>
extern VALUE rb_cEncoding;
int rb_encdb_alias(const char *alias, const char *orig);
/*
* Add alias to an existing encoding
*
* Encoding.add_alias('hebrew', 'Windows-1255') -> 'hebrew'
*
*/
VALUE rb_add_alias(VALUE self, VALUE alias, VALUE orig)
{
if (rb_encdb_alias(RSTRING_PTR(alias), RSTRING_PTR(orig)) == -1) {
return Qnil;
} else {
return alias;
}
}
void Init_enc_alias() {
rb_define_singleton_method(rb_cEncoding, "add_alias", rb_add_alias, 2);
}
You can force a new definition of Encoding.aliases. It may or may be not useful for your purposes:I do not know if it will be picked up by other classes; it should but it may not.
Encoding.instance_eval <<__END
alias :orig_aliases :aliases
def aliases
orig_aliases.update("x-mac-greek" => "macGreek")
end
__END

Resources