Class NtSerializer
- java.lang.Object
-
- org.aksw.limes.core.io.serializer.NtSerializer
-
- All Implemented Interfaces:
ISerializer
- Direct Known Subclasses:
TabSeparatedSerializer
public class NtSerializer extends Object implements ISerializer
Implements a simple serializer that generates NTriple files.- Version:
- Nov 25, 2015
- Author:
- Axel-C. Ngonga Ngomo (ngonga@informatik.uni-leipzig.de), Mohamed Sherif (sherif@informatik.uni-leipzig.de)
-
-
Constructor Summary
Constructors Constructor Description NtSerializer()NtSerializer(HashMap<String,String> prefixes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStatement(String subject, String predicate, String object, double similarity)Adds a triple to the buffer of the serializer.booleanclose()Closes the output filestatic Stringexpand(String s, String predicate)Expands a string by replacing a prefix by its full valuevoidflush()FilegetFile(String fileName)Method to open the file with the specific nameStringgetFileExtension()StringgetName()booleanopen(String file)Opens the output filevoidprintPrefixes(Map<String,String> prefixMap, String file)Method to print prefixes: "@prefix key: url ."voidprintStatement(String subject, String predicate, String object, double similarity)Writes in the file statement by statement.voidsetFolderPath(File folder)Method to set the folder where Serializations should be saved to.voidsetPrefixes(Map<String,String> prefixes)Sets the prefixes to be used in the file.voidwriteToFile(AMapping mapping, String predicate, String file)Gets a mapping and serializes it to a file in the N3 format.
-
-
-
Method Detail
-
expand
public static String expand(String s, String predicate)
Expands a string by replacing a prefix by its full value- Parameters:
s- Input stringpredicate- Predicate to expand with- Returns:
- Expanded version of s
-
addStatement
public void addStatement(String subject, String predicate, String object, double similarity)
Description copied from interface:ISerializerAdds a triple to the buffer of the serializer. Requires the method open to have been carried out- Specified by:
addStatementin interfaceISerializer- Parameters:
subject- The subject of the triplepredicate- The predicate of the tripleobject- The object of the triplesimilarity- value
-
flush
public void flush()
-
writeToFile
public void writeToFile(AMapping mapping, String predicate, String file)
Gets a mapping and serializes it to a file in the N3 format. The method assume that the class already knows all the prefixes used in the uris and expands those.- Specified by:
writeToFilein interfaceISerializer- Parameters:
mapping- Mapping to serializepredicate- Predicate to use while serializingfile- File in which the mapping is to be serialized
-
printStatement
public void printStatement(String subject, String predicate, String object, double similarity)
Writes in the file statement by statement. Rather slow, not to be used- Specified by:
printStatementin interfaceISerializer- Parameters:
subject- Source object of a mapping, subject of the triple to be writtenpredicate- Predicate to be writtenobject- Target object of a mapping, object of the triple to be writtensimilarity- Similarity achieved by the subject and object
-
printPrefixes
public void printPrefixes(Map<String,String> prefixMap, String file)
Method to print prefixes: "@prefix key: url ."- Parameters:
prefixMap- to be printedfile- file name
-
close
public boolean close()
Description copied from interface:ISerializerCloses the output file- Specified by:
closein interfaceISerializer- Returns:
- true if the file was closed successfully, else false
-
open
public boolean open(String file)
Description copied from interface:ISerializerOpens the output file- Specified by:
openin interfaceISerializer- Parameters:
file- Path to the file in which the output is to be written- Returns:
- true if opening was carried out successfully, else false.
-
getName
public String getName()
- Specified by:
getNamein interfaceISerializer- Returns:
- name
-
setPrefixes
public void setPrefixes(Map<String,String> prefixes)
Description copied from interface:ISerializerSets the prefixes to be used in the file.- Specified by:
setPrefixesin interfaceISerializer- Parameters:
prefixes- List of prefixes to use
-
getFileExtension
public String getFileExtension()
- Specified by:
getFileExtensionin interfaceISerializer- Returns:
- file extension
-
getFile
public File getFile(String fileName)
Description copied from interface:ISerializerMethod to open the file with the specific name- Specified by:
getFilein interfaceISerializer- Parameters:
fileName- string- Returns:
- file instance
-
setFolderPath
public void setFolderPath(File folder)
Description copied from interface:ISerializerMethod to set the folder where Serializations should be saved to.- Specified by:
setFolderPathin interfaceISerializer- Parameters:
folder- File which points to the folder to serialize within.
-
-