/** * Returns the primary thing this sentence is talking about. More precisely: Returns any subject * or a passive subject of the sentence, or the root if none applies. * * @param graph * @return */ public static IndexedWord getSubject(SemanticGraph graph) { if (graph.isEmpty()) { return null; } GrammaticalRelation[] subjects = { EnglishGrammaticalRelations.NOMINAL_SUBJECT, EnglishGrammaticalRelations.NOMINAL_PASSIVE_SUBJECT, EnglishGrammaticalRelations.CLAUSAL_SUBJECT, EnglishGrammaticalRelations.CLAUSAL_PASSIVE_SUBJECT }; IndexedWord firstRoot = graph.getFirstRoot(); List<IndexedWord> children = graph.getChildrenWithRelns(firstRoot, Arrays.asList(subjects)); if (children != null && children.size() > 0) { assert children.size() == 1; // not really dangerous. But we need to change our implementation to return a list, // if there are more than one subject. return children.get(0); } // return null; return graph.getFirstRoot(); // in a subject-less sentence, the root is as good as the subject }