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.utilities.datastructures; 020 021import com.google.common.collect.ComparisonChain; 022import org.apache.jena.rdf.model.RDFNode; 023import org.apache.jena.sparql.util.NodeComparator; 024import org.dllearner.kb.extraction.LiteralNode; 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 */ 031public 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.equals(t.b) && a.equals(t.a); 048 } 049 050 @Override 051 public int compareTo(RDFNodeTuple t) { 052 NodeComparator comparator = new NodeComparator(); 053 return ComparisonChain.start(). 054 compare(a.asNode(), t.a.asNode(), comparator). 055 compare(b.asNode(), t.b.asNode(), comparator). 056 result(); 057 } 058 059 public boolean aPartContains(String partOf) { 060 return a.toString().contains(partOf); 061 } 062 063 public boolean bPartContains(String partOf) { 064 return b.toString().contains(partOf); 065 } 066 067 068 public String getNTriple (String subject){ 069 String ret = "<"+subject+"> "; 070 ret+="<"+a.toString()+"> "; 071 if(b.isLiteral()){ 072 ret+=new LiteralNode(b).getNTripleForm(); 073 074 }else{ 075 ret+="<"+b.toString()+"> "; 076 } 077 ret+="."; 078 return ret; 079 } 080 081}