All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.articulate.sigma.nlg.Preposition Maven / Gradle / Ivy

Go to download

Sigma knowledge engineering system is an system for developing, viewing and debugging theories in first order logic. It works with Knowledge Interchange Format (KIF) and is optimized for the Suggested Upper Merged Ontology (SUMO) www.ontologyportal.org.

The newest version!
package com.articulate.sigma.nlg;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;

import java.util.List;
import java.util.Map;

/**
 * Handles preposition behavior for case roles. Handles both default behavior--e.g. "the direction case role
 * is usually marked with the preposition 'toward'"--as well as exceptions for certain verbs.
 */
public class Preposition {
    // Mappings for verb + preposition.

    private static final Multimap defaultPrepositions = ArrayListMultimap.create();

    // Read this as: "Usually destinations follow the preposition 'to'."
    private static final List DESTINATION_PREPOSITIONS = Lists.newArrayList("to");

    private static final List DIRECTION_PREPOSITIONS = Lists.newArrayList("toward");

    private static final List EVENTPARTLYLOCATED_PREPOSITIONS = Lists.newArrayList("in");

    private static final List INSTRUMENT_PREPOSITIONS = Lists.newArrayList("with");

    private static final List ORIGIN_PREPOSITIONS = Lists.newArrayList("from");

    private static final List PATH_PREPOSITIONS = Lists.newArrayList("along");

    private static final List RESOURCE_PREPOSITIONS = Lists.newArrayList("out of", "from");

    // Insert default mappings into the multimap.
    static {
        defaultPrepositions.putAll(CaseRole.INSTRUMENT, INSTRUMENT_PREPOSITIONS);
        defaultPrepositions.putAll(CaseRole.DESTINATION, DESTINATION_PREPOSITIONS);
        defaultPrepositions.putAll(CaseRole.DIRECTION, DIRECTION_PREPOSITIONS);
        defaultPrepositions.putAll(CaseRole.EVENTPARTLYLOCATED, EVENTPARTLYLOCATED_PREPOSITIONS);
        defaultPrepositions.putAll(CaseRole.ORIGIN, ORIGIN_PREPOSITIONS);
        defaultPrepositions.putAll(CaseRole.PATH, PATH_PREPOSITIONS);
        defaultPrepositions.putAll(CaseRole.RESOURCE, RESOURCE_PREPOSITIONS);
    }

    // Mappings for verbs that fall out of the default preposition-case role behavior.
    private static final Map> specialVerbPrepositionBehaviorMap = Maps.newHashMap();
    // FIXME: Uncomment when benefits is made a CaseRole
//    static {
//        // "The benefits role for the verb 'help' does not take a preposition."
//        Multimap prepsForCaseRole = ArrayListMultimap.create();
//        prepsForCaseRole.put(CaseRole.BENEFITS, "");
//        specialVerbPrepositionBehaviorMap.put("help", prepsForCaseRole);
//    }

    public static List getPrepositionForCaseRole(String verb, CaseRole caseRole)   {
        // The default is empty string--no preposition.
        List retList = Lists.newArrayList("");

        // First try exception list.
        if (specialVerbPrepositionBehaviorMap.containsKey(verb) && specialVerbPrepositionBehaviorMap.get(verb).containsKey(caseRole))    {
            Multimap mm = specialVerbPrepositionBehaviorMap.get(verb);
            retList = Lists.newArrayList(mm.get(caseRole));
        }
        // Use the default.
        else    {
            retList = Lists.newArrayList(defaultPrepositions.get(caseRole));
            // If retList is empty, insert empty string into the first element, representing no preposition.
            if (retList.isEmpty())  {
                retList.add("");
            }
        }

        return retList;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy