Class 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 Detail

      • NtSerializer

        public NtSerializer()
    • 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 string
        predicate - 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: ISerializer
        Adds a triple to the buffer of the serializer. Requires the method open to have been carried out
        Specified by:
        addStatement in interface ISerializer
        Parameters:
        subject - The subject of the triple
        predicate - The predicate of the triple
        object - The object of the triple
        similarity - 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:
        writeToFile in interface ISerializer
        Parameters:
        mapping - Mapping to serialize
        predicate - Predicate to use while serializing
        file - 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:
        printStatement in interface ISerializer
        Parameters:
        subject - Source object of a mapping, subject of the triple to be written
        predicate - Predicate to be written
        object - Target object of a mapping, object of the triple to be written
        similarity - 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 printed
        file - file name
      • close

        public boolean close()
        Description copied from interface: ISerializer
        Closes the output file
        Specified by:
        close in interface ISerializer
        Returns:
        true if the file was closed successfully, else false
      • open

        public boolean open​(String file)
        Description copied from interface: ISerializer
        Opens the output file
        Specified by:
        open in interface ISerializer
        Parameters:
        file - Path to the file in which the output is to be written
        Returns:
        true if opening was carried out successfully, else false.
      • setPrefixes

        public void setPrefixes​(Map<String,​String> prefixes)
        Description copied from interface: ISerializer
        Sets the prefixes to be used in the file.
        Specified by:
        setPrefixes in interface ISerializer
        Parameters:
        prefixes - List of prefixes to use
      • getFile

        public File getFile​(String fileName)
        Description copied from interface: ISerializer
        Method to open the file with the specific name
        Specified by:
        getFile in interface ISerializer
        Parameters:
        fileName - string
        Returns:
        file instance
      • setFolderPath

        public void setFolderPath​(File folder)
        Description copied from interface: ISerializer
        Method to set the folder where Serializations should be saved to.
        Specified by:
        setFolderPath in interface ISerializer
        Parameters:
        folder - File which points to the folder to serialize within.