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.utilities.datastructures;
021
022 import org.dllearner.kb.extraction.LiteralNode;
023
024 import com.hp.hpl.jena.rdf.model.RDFNode;
025
026 /**
027 * A container which can hold two Strings, mainly used as a helper.
028 * Also used as pre form, if you want to create triple, that have the same subject
029 * @author Sebastian Hellmann
030 */
031 public class RDFNodeTuple implements Comparable<RDFNodeTuple>{
032
033 public RDFNode a;
034 public RDFNode b;
035
036 public RDFNodeTuple(RDFNode a, RDFNode b) {
037 this.a = a;
038 this.b = b;
039 }
040
041 @Override
042 public String toString() {
043 return "<" + a.toString() + "|" + b.toString() + ">";
044 }
045
046 public boolean equals(RDFNodeTuple t) {
047 return ((b.toString().equals(t.b.toString())) && (a.toString().equals(t.a)));
048 }
049
050 public int compareTo(RDFNodeTuple t){
051 int comp = a.toString().compareTo(t.a.toString());
052 if( comp == 0 ){
053 return b.toString().compareTo(t.b.toString());
054 }else return comp;
055 }
056
057 public boolean aPartContains(String partOf) {
058 return a.toString().contains(partOf);
059 }
060
061 public boolean bPartContains(String partOf) {
062 return b.toString().contains(partOf);
063 }
064
065
066 public String getNTriple (String subject){
067 String ret = "<"+subject+"> ";
068 ret+="<"+a.toString()+"> ";
069 if(b.isLiteral()){
070 ret+=new LiteralNode(b).getNTripleForm();
071
072 }else{
073 ret+="<"+b.toString()+"> ";
074 }
075 ret+=".";
076 return ret;
077 }
078
079 }