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

rationals.algebra.RationalMatrix Maven / Gradle / Ivy

Go to download

HermiT is reasoner for ontologies written using the Web Ontology Language (OWL). Given an OWL file, HermiT can determine whether or not the ontology is consistent, identify subsumption relationships between classes, and much more. This is the maven build of HermiT and is designed for people who wish to use HermiT from within the OWL API. It is now versioned in the main HermiT version repository, although not officially supported by the HermiT developers. The version number of this package is a composite of the HermiT version and an value representing releases of this packaged version. So, 1.3.7.1 is the first release of the mavenized version of HermiT based on the 1.3.7 release of HermiT. This package includes the Jautomata library (http://jautomata.sourceforge.net/), and builds with it directly. This library appears to be no longer under active development, and so a "fork" seems appropriate. No development is intended or anticipated on this code base.

There is a newer version: 1.3.8.4
Show newest version
/*______________________________________________________________________________
 * 
 * Copyright 2005 Arnaud Bailly - NORSYS/LIFL
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * (1) Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 * (2) Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 * (3) The name of the author may not be used to endorse or promote
 *     products derived from this software without specific prior
 *     written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Created on 10 mai 2005
 *
 */
package rationals.algebra;

import java.util.Iterator;
import java.util.Set;

import rationals.Rational;
import rationals.State;
import rationals.Transition;
import rationals.expr.Letter;
import rationals.expr.Plus;
import rationals.expr.RationalExpr;

/**
 * A matrix for representing regular languages.
 * 

* The cell of the matrix are rational expressions made from concatenation, * epsilon, letters and union. * * @author nono * @version $Id: RationalMatrix.java 2 2006-08-24 14:41:48Z oqube $ * @see rationals.expr */ public class RationalMatrix { private Matrix init; private Matrix fini; private Matrix transitions; /** * @return Returns the fini. */ public Matrix getFini() { return fini; } /** * @param fini The fini to set. */ public void setFini(Matrix fini) { this.fini = fini; } /** * @return Returns the init. */ public Matrix getInit() { return init; } /** * @param init The init to set. */ public void setInit(Matrix init) { this.init = init; } /** * @return Returns the transitions. */ public Matrix getTransitions() { return transitions; } /** * @param transitions The transitions to set. */ public void setTransitions(Matrix transitions) { this.transitions = transitions; } /** * Construct the matrix of a rational language. * * @param rat * a Rational language. */ public RationalMatrix(Rational rat) { Set st = rat.states(); int n = st.size(); init = Matrix.zero(1,n,RationalExpr.zero); fini = Matrix.zero(n,1,RationalExpr.zero); transitions = Matrix.zero(n,n,RationalExpr.zero); State[] sta = (State[]) rat.states().toArray(new State[n]); /* fill matrices */ for (int i = 0; i < sta.length; i++) { if (sta[i].isInitial()) init.matrix[0][i] = Letter.epsilon; else init.matrix[0][i] = RationalExpr.zero; if (sta[i].isTerminal()) fini.matrix[i][0] = Letter.epsilon; else fini.matrix[i][0] = RationalExpr.zero; /* transitions */ for (int j = 0; j < n; j++) { Set trs = rat.deltaFrom(sta[i], (State) sta[j]); RationalExpr re = null; for (Iterator it = trs.iterator(); it.hasNext();) { Transition tr = (Transition) it.next(); Object o = tr.label(); Letter l = (o == null) ? Letter.epsilon : new Letter(o); if (re == null) re = l; else re = new Plus(re, l); } transitions.matrix[i][j] = re == null ? RationalExpr.zero : re; } } } /** * Compute words from this rational whose length is * n. * * @param n * @return */ public Matrix nwords(int n) { Matrix res = transitions.power(n,Matrix.zero(transitions.getLine(),transitions.getLine(),RationalExpr.zero)); /* compute product for init and fini */ Matrix in = (Matrix)init.mult(res); return (Matrix)in.mult(fini); } public String toString() { return init.toString() + '\n'+ transitions.toString() + '\n'+fini.toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy