001 /**
002 * Copyright (C) 2007-2011, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 */
019
020 package org.dllearner.kb.extraction;
021
022 import java.util.List;
023 import java.util.SortedSet;
024
025 import org.apache.log4j.Logger;
026 import org.dllearner.kb.aquisitors.TupleAquisitor;
027 import org.dllearner.kb.manipulator.Manipulator;
028 import org.semanticweb.owlapi.model.IRI;
029
030
031
032 /**
033 * Abstract class. defines functions to expand the nodes
034 *
035 * @author Sebastian Hellmann
036 *
037 */
038 public abstract class Node {
039 private static Logger logger = Logger
040 .getLogger(Node.class);
041
042 // make sure no information is missed during the transition to OWLAPI
043 public static final boolean DEBUGTAIL = false;
044
045 protected String uri;
046 // protected String type;
047 protected boolean expanded = false;
048
049 public Node(String uri) {
050 this.uri = uri;
051 }
052
053 /**
054 * Nodes are expanded with a certain context, given by the typedSparqlQuery
055 * and the manipulator
056 *
057 * @param manipulator
058 * @return Vector<Node> all Nodes that are new because of expansion
059 */
060 public abstract List<Node> expand(
061 TupleAquisitor TupelAquisitor, Manipulator manipulator);
062
063 /**
064 * gets type defs for properties like rdf:type SymmetricProperties
065 *
066 * @param manipulator
067 */
068 public abstract List<BlankNode> expandProperties(
069 TupleAquisitor TupelAquisitor, Manipulator manipulator, boolean dissolveBlankNodes);
070
071 /**
072 * output
073 *
074 * @return a set of n-triple
075 */
076 public abstract SortedSet<String> toNTriple();
077
078 public abstract void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector);
079
080 /*
081
082 @Override
083 public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){
084
085 }
086 */
087
088 @Override
089 public String toString() {
090 return "Node: " + uri + ":" + this.getClass().getSimpleName();
091
092 }
093
094 public String getURIString() {
095 return uri;
096 }
097
098
099 public IRI getIRI() {
100 return IRI.create(uri);
101 }
102
103 public String getNTripleForm(){
104 return "<"+uri+"> ";
105 }
106
107 public boolean isExpanded(){
108 return expanded;
109 }
110
111 public void tail( String tailmessage){
112 boolean ignore = !DEBUGTAIL;
113 tail(ignore, tailmessage);
114 }
115
116 public void tail(boolean ignore, String tailmessage){
117
118 String message = "difficult tuple. Subject is: "+ this.getURIString()+" of type: "+this.getClass().getSimpleName()+" " +
119 "info: "+tailmessage;
120 if(ignore){
121 if(DEBUGTAIL){
122 logger.info("IGNORING: "+message);
123 }else {
124 logger.debug("IGNORING: "+message);
125 }
126
127
128 }else{
129 logger.warn(message);
130 logger.error("exiting ");
131 System.exit(0);
132 }
133
134 }
135
136 }