/* ModelUtil.java * * Copyright (c) 2003 by Benja Fallenstein * * This file is part of Fenfire. * * Fenfire is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Fenfire is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * */ /* * Written by Benja Fallenstein */ package gzz.loom; import java.util.*; import com.hp.hpl.mesa.rdf.jena.model.*; /** Utility methods for RDF models. */ public class ModelUtil { /** Get the classes used in an RDF model. * A resource is considered a class if it is * the object of an rdf:type triple. */ public static Set getClasses(Model m) throws RDFException { Set classes = new HashSet(); RDFVocab rdf = new RDFVocab(m); for(StmtIterator iter = m.listStatements(); iter.hasNext();) { Statement stmt = iter.next(); Property p = stmt.getPredicate(); if(p.equals(rdf.type)) classes.add(stmt.getObject()); } return classes; } /** Get the set of all properties of all statements in a model. * Omitted from this are the 'numeric' properties: * rdf:_1, rdf:_2 etc. */ public static Set getProperties(Model m) throws RDFException { Set properties = new HashSet(); RDFVocab rdf = new RDFVocab(m); for(StmtIterator iter = m.listStatements(); iter.hasNext();) { Statement stmt = iter.next(); Property p = stmt.getPredicate(); if(!rdf.isNumericProperty(p)) properties.add(p); } return properties; } }