I know Java and I know C#.
I am a noobie with the JBoss Drools "Guvnor" and just their DRL rules language in general. I need a little help on how to use dates and times correctly in the LHS of rules.
For example, I have to assure data quality in a health care system. Obviously, each patient has a DOB in their record and it is of type java.util.Date.
Okay, so say I want to ensure that the DOB in the data passed as Facts is indeed before today's date. I know, for instance, in C#, you can get the current date/time by saying DateTime.Now.
I want to add a rule in Guvnor that says (and this is pseudo-code):
WHEN
patient DOB is before NOW
THEN
mark patient as valid
My Patient fact is:
declare Patient
patientID: integer
firstName: text
lastName: text
dateOfBirth: java.util.Date
end
I also have a Dose fact, with a patientID field to link it to what patient got what dose:
declare Dose
doseID: integer
patientID: integer
administeredDate: java.util.Date
amount: integer
end
Also, say a medication is released on a certain year, 1995, and I want to also check that a dose for a given patient is not administered prior to that year.
How do I do these two? I've tried Googling and Googling but all I get is links to the (utterly-useless) Guvnor User Guide which is pretty badly-written in that it doesn't contain this basic information, i.e., how dates and times work and are written in DRL syntax.
Thank you.
As always there are more than one way to do this. Here is one.
function Date currentTime(){
// The content of this method is Java
return new Date();
}
RULE "my rule"
WHEN
patient : Patient( dateOfBirth < currentTime() )
THEN
// Everything in THEN part is Java
patient.setValid(true); // Notice I added a valid field into the fact type
update(patient);
END
The other rule you asked for
Also, say a medication is released on a certain year, 1995, and I want to also check that a dose for a given patient is not administered prior to that year.
RULE "Second Rule"
WHEN
patient : Patient()
not Dose( patientId == patient.patientId, administeredDate < 01-Jan-1995 ) // The date format can be changed if you want to.
WHEN
System.out.println( "Patient " + patient.getFirstName + " " +patient.getLastName() + " was not given a dose before." );
END
The Guvnor user guide does not cover the language basics. You can find them from here. Guvnor is meant to provide you guided editors for writing the DRL or storing the files containing DRL. You check what the guided rule would look like if it was written in DRL by pressing the "View Source" button that is in each asset editor that produces DRL.
Related
In ISO-3166, when it comes to the country, there is a difference between "short name" and "full name".
For example, Denmark (link to iso.org reference : https://www.iso.org/obp/ui/#iso:code:3166:DK).
Its country code would be DK and DNK (alpha-2 and alpha-3), its numeric code is 208, its short name is 'Denmark', and its full name is 'the Kingdom of Denmark'.
For my current project, I have all the information I need except full name.
Does anyone know of a way to get that kind of data?
Java's in-built localization doesn't support official country names.
Here's the entry for Denmark in the localization data
DK=Denmark
You can use a REST API like https://restcountries.eu/, or I found this CSV file which seems to contain what you want. You will need to parse it.
Does someone know a way to retrieve a list of nationalities in Java ? Few precisions : I do not need a list of countries but a list of nationalities. I do not need a list of languages, but a list of nationalities. I've tried to twist Locale API, without result.
And icing on the cake, I need to display nationalities in a specific languages.For example, with Brazil, I need to display a 'brazilian' in english, a 'brésilien' in french and a 'brasilero' in spanish.
Does someone have an idea ?
Java doesn't contain a list of nationalities as far as I'm aware. The Locale class just gives a list of regions as stated in the javadoc. It would be helpful in your situation, but not for a lot.
From what i gather, you're going to have to create your own list of nationalities, and the name of the nationality in each language - not too hard.
To do the language part, internationalization will be helpful. It allows you to get the users region and set a language depending on where the user is from. It also allows formatting of numbers, text and dates.
Look at this stack overflow answer specifically for how to get the names of the nationalities in different languages. Basically, you create a different file for each language and inside the file are key-value pares. So the English file will look a bit like this:
nationality.english = English
nationality.german = German
nationality.russian = Russian
and the German file will be similar to:
nationality.english = Englisch
nationality.german = Deutsche
nationality.russian = Russisch
then depending on what language you want the nationalities displayed in, you just get the text from the language file using the key (e.g. nationality.russian).
To do the nationality part, you can create an enum that contains all the nationalities. For example:
public enum Nationalities{
ENGLISH,
GERMAN;
//And so on
}
See here if you are new to java enums.
You will probably want to add a bit more information in the enum class, such as the county and what the key for the nationality name is.
To pull it all together, you get the region of the user and set the language file for the region. Then for each listed nationality, you get the name of it from the language file.
I am planning to do some data tuning on my data.
Situation-I have a data which has a field country. It contains user input country names( It might contain spelling mistakes or different country names for same country like US/U.S.A/United States for USA). I have a list of correct country names.
What I want- To predict which closest country it is referring to. For example- If U.S. is given then it will change to USA(correct country name in our list).
Is there any way I can do it using Java or opennlp or any other method?
You can use Getty API . It will give you abbreviations of country name. Just play on this API.
OR
You can also use Levenshtein Distance to get most closest country name.
Try this out. Will help you.
You can try Google's auto complete location api to your text box or select.
if you will use this api then you will get google like auto complete intellisence while typing.
visit link
If you have the city or state information that is sanitized then you could do a look up of the country.
You could also define aliases in your list of country names and point the aliases to the preferred notation. For example, US, United States, USA all are aliases of U.S.A. You could make the program to append to alias database so that it improves as it is being used. You might have do multiple passes over the data and also certain amount of manual work is involved.
My application gets in input a certain amount of String, suppose the name of the "object" I'm looking for, and other fields like the year when an artist was born or the last album he made.
By the way the application has no knowledge on the type of the object in input, so what I'm trying to do is making an MQL query that, given the name of the object and other values (in any field, as I don't know the type of what I'm querying), returns me the type of what I searched. Once I get its type, I could for example make a better query asking for specifical fields.
As we all know, an example is worth thousand words, so let's assume my input is "The Police" and "So Lonely", one of their songs. I just know "The Police" is the name of what I'm looking for, but I don't know nothing about "So Lonely", so I should insert it someway in the query to get better results, without the knowledge of its type.
My first basic query is:
[{
"name": "The Police",
"type": []
}]
and it works, but I can't refine my search including so lonely, that could narrow the search output.
Any hint?
Another thing I need to accomplish, once I do the above (and still no idea on how to do it!) would be printing a summary of the entity i found. For example above, I would not have ALL the information about "The Police", but only basic general fields, that could be albums, the year they were born.
Is this possible to do something like that without the knowledge of what I found?
In my database I have a table containing localized cities.
Cities
_id |name_en |name_de |name_it
0 |Rome |Rom |Roma
1 |Munich |München |Monaco
...
Now I want show a ListView where each line exists of all names started by the name in the users language. Also the whole list should be sorted by the city in the users language.
Which is the right design-pattern for this kind of problem?
This is quite a broad question, but here's one general approach:
Get the user's current language ( Get the current language in device )
Query your database with this language code
Bind the returned Cursor to your ListView
Please post your relevant code if you want specific help.
Obviously you need to decide what column to use for SQL request (for both stating which column to retrieve and by which column to sort). So your column names should be public constants. And you need to have a method to return a column name (one of the constants) depending on the current device locale. Use one of the constants as a fallback if the locale does not match any known for the application locales.