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.ArrayList;
022import java.util.List;
023import java.util.SortedSet;
024import java.util.TreeSet;
025
026import org.apache.log4j.Logger;
027import org.dllearner.kb.aquisitors.TupleAquisitor;
028import org.dllearner.kb.manipulator.Manipulator;
029
030import org.apache.jena.rdf.model.Literal;
031import org.apache.jena.rdf.model.RDFNode;
032
033/**
034 * A node in the graph that is a Literal.
035 * 
036 * @author Sebastian Hellmann
037 * 
038 */
039public class LiteralNode extends Node {
040        
041        private Literal l;
042        
043        @SuppressWarnings("unused")
044        private static Logger logger = Logger
045                .getLogger(LiteralNode.class);
046
047
048        public LiteralNode(String uri) {
049                super(uri);
050                
051        }
052        
053        public LiteralNode(RDFNode node) {
054                super(node.toString());
055                l = (Literal) node;
056        }
057        
058        public Literal getLiteral(){
059                return l;
060        }
061
062        // expands all directly connected nodes
063        @Override
064        public List<Node> expand(TupleAquisitor tupelAquisitor, Manipulator manipulator) {
065                return new ArrayList<>();
066        }
067        
068        
069
070        // gets the types for properties recursively
071        @Override
072        public List<BlankNode>  expandProperties(TupleAquisitor tupelAquisitor, Manipulator manipulator, boolean dissolveBlankNodes) {
073                return new ArrayList<>();
074        }
075
076        @Override
077        public SortedSet<String> toNTriple() {
078                return new TreeSet<>();
079        }
080
081        
082        
083        @Override
084        public String getNTripleForm() {
085                String quote = "\\\"";
086                quote = "&quot;";
087                String retVal = l.getLexicalForm();
088                retVal = retVal.replaceAll("\n", "\\n");
089                retVal = retVal.replaceAll("\"", quote);
090                retVal = "\""+retVal+"\"";
091                if(l.getDatatypeURI()!=null) {
092                        return retVal +"^^<"+l.getDatatypeURI()+">";
093                }else {
094                        return retVal+((l.getLanguage().length()==0)?"":"@"+l.getLanguage());
095                }
096                
097        }
098        
099        @Override
100        public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){
101                
102        }
103        
104        public boolean isDouble(){
105                try{
106                        return l.getDatatypeURI() != null && l.getDatatypeURI().contains("double");
107                }catch (Exception e) {
108                        return false;
109                }
110        }
111        
112        public boolean isFloat(){
113                try{
114                        return l.getDatatypeURI() != null && l.getDatatypeURI().contains("float");
115                }catch (Exception e) {
116                        return false;
117                }
118        }
119        
120        public boolean isInt(){
121                try{
122                        return l.getDatatypeURI() != null && l.getDatatypeURI().contains("int");
123                }catch (Exception e) {
124                        return false;
125                }
126        }
127        
128        public boolean isBoolean(){
129                try{
130                        return l.getDatatypeURI() != null && l.getDatatypeURI().contains("boolean");
131                }catch (Exception e) {
132                        return false;
133                }
134        }
135        
136        public boolean isString(){
137                try{
138                        l.getString();
139                        return true;
140                }catch (Exception e) {
141                        return false;
142                }
143        }
144        public boolean hasLanguageTag(){
145                return (!(l.getLanguage().length()==0));
146        }
147        
148        
149        
150        
151
152}