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

com.thesett.aima.logic.fol.VariableAndFunctorInternerImpl Maven / Gradle / Ivy

Go to download

Library of code developed from 'Artificial Intelligence a Modern Approach', Prentice Hall.

There is a newer version: 0.8.3
Show newest version
/*
 * Copyright The Sett Ltd, 2005 to 2014.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.thesett.aima.logic.fol;

import com.thesett.aima.attribute.impl.IdAttribute;

/**
 * VariableAndFunctorInternerImpl provides interners for variable and functor names in specified namespaces.
 *
 * 

*
CRC Card
Responsibilities Collaborations *
Provide symbol table for functors names. *
Provide symbol table for variable names. *
* * @author Rupert Smith */ public class VariableAndFunctorInternerImpl implements VariableAndFunctorInterner { /** Holds the interner that turns variable names into indexed integers. */ private IdAttribute.IdAttributeFactory variableInterningFactory; /** Holds the interner that turns functor names and arities into indexed integers. */ private IdAttribute.IdAttributeFactory functorInterningFactory; /** * Creates an interner for variable and functor names, with the names created under the specified name spaces. * * @param variableNameSpace The name space for variables. * @param functorNameSpace The name space for functors. */ public VariableAndFunctorInternerImpl(String variableNameSpace, String functorNameSpace) { variableInterningFactory = IdAttribute.getFactoryForClass(variableNameSpace); functorInterningFactory = IdAttribute.getFactoryForClass(functorNameSpace); } /** {@inheritDoc} */ public IdAttribute.IdAttributeFactory getFunctorInterner() { return functorInterningFactory; } /** {@inheritDoc} */ public IdAttribute.IdAttributeFactory getVariableInterner() { return variableInterningFactory; } /** {@inheritDoc} */ public int internFunctorName(String name, int numArgs) { FunctorName functorName = new FunctorName(name, numArgs); return getFunctorInterner().createIdAttribute(functorName).ordinal(); } /** {@inheritDoc} */ public int internFunctorName(FunctorName name) { return getFunctorInterner().createIdAttribute(name).ordinal(); } /** {@inheritDoc} */ public int internVariableName(String name) { return getVariableInterner().createIdAttribute(name).ordinal(); } /** {@inheritDoc} */ public String getVariableName(int name) { if (name < 0) { return "_G" + (-name); } else { return getVariableInterner().getAttributeFromInt(name).getValue(); } } /** {@inheritDoc} */ public String getVariableName(Variable variable) { return getVariableName(variable.getName()); } /** {@inheritDoc} */ public FunctorName getDeinternedFunctorName(int name) { return getFunctorInterner().getAttributeFromInt(name).getValue(); } /** {@inheritDoc} */ public String getFunctorName(int name) { return getFunctorInterner().getAttributeFromInt(name).getValue().getName(); } /** {@inheritDoc} */ public int getFunctorArity(int name) { return getFunctorInterner().getAttributeFromInt(name).getValue().getArity(); } /** {@inheritDoc} */ public FunctorName getFunctorFunctorName(Functor functor) { return getDeinternedFunctorName(functor.getName()); } /** {@inheritDoc} */ public String getFunctorName(Functor functor) { return getFunctorName(functor.getName()); } /** {@inheritDoc} */ public int getFunctorArity(Functor functor) { return getFunctorArity(functor.getName()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy