001/** 002 * Copyright (C) 2007 - 2016, 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 */ 019package org.dllearner.kb.extraction; 020 021import java.util.List; 022import java.util.SortedSet; 023 024import org.apache.log4j.Logger; 025import org.dllearner.kb.aquisitors.TupleAquisitor; 026import org.dllearner.kb.manipulator.Manipulator; 027import org.semanticweb.owlapi.model.IRI; 028 029 030 031/** 032 * Abstract class. defines functions to expand the nodes 033 * 034 * @author Sebastian Hellmann 035 * 036 */ 037public abstract class Node { 038 private static Logger logger = Logger 039 .getLogger(Node.class); 040 041 // make sure no information is missed during the transition to OWLAPI 042 public static final boolean DEBUGTAIL = false; 043 044 protected String uri; 045 // protected String type; 046 protected boolean expanded = false; 047 048 public Node(String uri) { 049 this.uri = uri; 050 } 051 052 /** 053 * Nodes are expanded with a certain context, given by the typedSparqlQuery 054 * and the manipulator 055 * 056 * @param manipulator the manipulator 057 * @return Vector<Node> all Nodes that are new because of expansion 058 */ 059 public abstract List<Node> expand( 060 TupleAquisitor TupelAquisitor, Manipulator manipulator); 061 062 /** 063 * gets type defs for properties like rdf:type SymmetricProperties 064 * 065 * @param manipulator the manipulator 066 */ 067 public abstract List<BlankNode> expandProperties( 068 TupleAquisitor TupelAquisitor, Manipulator manipulator, boolean dissolveBlankNodes); 069 070 /** 071 * output 072 * 073 * @return a set of n-triple 074 */ 075 public abstract SortedSet<String> toNTriple(); 076 077 public abstract void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector); 078 079 /* 080 081 @Override 082 public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ 083 084 } 085 */ 086 087 @Override 088 public String toString() { 089 return "Node: " + uri + ":" + this.getClass().getSimpleName(); 090 091 } 092 093 public String getURIString() { 094 return uri; 095 } 096 097 098 public IRI getIRI() { 099 return IRI.create(uri); 100 } 101 102 public String getNTripleForm(){ 103 return "<"+uri+"> "; 104 } 105 106 public boolean isExpanded(){ 107 return expanded; 108 } 109 110 public void tail( String tailmessage){ 111 boolean ignore = !DEBUGTAIL; 112 tail(ignore, tailmessage); 113 } 114 115 public void tail(boolean ignore, String tailmessage){ 116 117 String message = "difficult tuple. Subject is: "+ this.getURIString()+" of type: "+this.getClass().getSimpleName()+" " + 118 "info: "+tailmessage; 119 if(ignore){ 120 if(DEBUGTAIL){ 121 logger.info("IGNORING: "+message); 122 }else { 123 logger.debug("IGNORING: "+message); 124 } 125 126 127 }else{ 128 logger.warn(message); 129 logger.error("exiting "); 130 System.exit(0); 131 } 132 133 } 134 135}