0

I am using the wikidata toolkit and I want to get a list of all events.

I wrote a EntityDocumentProcessor, where I want to filter for the events out of my dump. Well I know that the event document has the id Q1190554 and that I have to somehow check if the instance of the current itemDocument is an "instance of" (P31) of an event.

@Override
public void processItemDocument(ItemDocument itemDocument) {
        boolean isEvent = false;
        for (StatementGroup statementGroup : itemDocument.getStatementGroups()) {
            switch (statementGroup.getProperty().getId()) {
                case "P31": // P31 is "instance of"
                    isEvent = containsValue(statementGroup, filterClass);
                    break;
                case "P279": // P279 is "subclass of"
                    if (!isEvent) {
                        isEvent = containsValue(statementGroup, filterClass);
                    }
                    break;
            }
        }
}



private boolean containsValue(StatementGroup statementGroup, Value value) {
    for (Statement s : statementGroup.getStatements()) {
        if (value.equals(s.getValue())) {
            return true;
        }
    }

    return false;
}

This approach worked pretty good for getting people. But the problem with events is that events like WW2 (https://www.wikidata.org/wiki/Q362) dont have the event directly mapped. The event is somewhere hidden. Does anyone knows a way how I can easily check if the current itemDocument is an event?

Safari
  • 3,302
  • 9
  • 45
  • 64

1 Answers1

0

You should follow the hierarchy of the subclass of of the particular instance of to a split. So starting from Q362 you will eventually reach: https://www.wikidata.org/wiki/Q350604 - armed conflict, the presumption being that WWII is everything until prior to that split, namely:
1) world war: https://www.wikidata.org/wiki/Q103495 and
2) war: https://www.wikidata.org/wiki/Q198, then
3) armed conflict: https://www.wikidata.org/wiki/Q350604 which splits to:

1) conflict: https://www.wikidata.org/wiki/Q180684, which now splits to
2) event: https://www.wikidata.org/wiki/Q1190554

And since you are only interested in events, I will do this recursively until I reach the event class.

marfi
  • 136
  • 8