dig-team / amie

Mavenized AMIE+Typing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clear output for AMIE rules

lgalarra opened this issue · comments

We should consider the output of the rules in different output formats, e.g., JSON. We could also clean the code to output all log messages to the standard error so that users can redirect the standard output to a file to get the rules.

I have the rules in a data frame and additional information in a separate dictionary.
image
Right now, I am trying to decipher from the rules how can I obtain the actual instance of a and b

example: I have
a associates_with b => a causes b

I want:
fever associates_with temperature => fever causes temperature.

Any lead on this will be appreciated.

Hi,

All the utilities to deal with rules and their predictions are available under https://github.com/lajus/amie/tree/master/rules/src/main/java/amie/rules/eval. In particular have a look at the class Predictor in the file Predictor.java. This class takes a set of rules and draw samples of their predictions (it is possible to tell the class to obtain all predictions). Do not hesitate to ask if you have more questions or doubts.

Best,
Luis

@lgalarra Thanks for your help. Probably because of my little to no experience in Java and the basic idea of rule mining, I tried a few workarounds on the predictor class, but none seemed to work.

While running the AMIE+, I limited my predictions to only a 'treat' edge; eventually, I was left with 70 rules which contain up to a 3-hop rule set. I will appreciate a pointer on getting:

relation1(a.name, h.name) ^ relation2(h.name, b.name) => (a.name, relation, b.name)

from

relation1(a, h) ^ relation2(h, b) => (a, relation, b)

image

Hi,

It is true that with the migration to the integer-encoded in-memory DB, things are a bit more complicated. I think you can still build upon the predictor class. You could do something like:

KB kb = new KB();
// Load the KB with the data used to train the rules
int sampleSize = Integer.MAX_VALUE; // If you want all the predictions
List<Rule> rules = new ArrayList<Rule>(AMIEParser.rules(new File(<PATH_TO_FILE_WITH_ONE_RULE_PER_LINE>)));
Predictor pp = new Predictor(kb, sampleSize);
for(Rule rule: rules){
	Object predictions = predictor.generatePredictions(rule);
	Collection<IntTriple> newPredictions = predictor.samplePredictions(predictions, rule);
        for (IntTriple triple : newPredictions) {
                String subject = KB.unmap(triple.first());
                String predicate = KB.unmap(triple.second());
                String object = KB.unmap(triple.third());
                // .... Here are your triples
        }
}	

You will need to change the code of the class Predictor to make the private method samplePredictions public.

Best,
Luis

@lgalarra This is insightful; I will try some workarounds with the snippet.
Thank you so much.