Class LETORInstanceWriter<U>

java.lang.Object
es.uam.eps.ir.relison.links.data.letor.io.LETORInstanceWriter<U>
Type Parameters:
U - type of the users.
All Implemented Interfaces:
InstanceSetWriter<U>

public class LETORInstanceWriter<U>
extends java.lang.Object
implements InstanceSetWriter<U>
Class for writing patterns in the LETOR format (for Learning TO Rank task). Format:
#featId1: description1 stats1
#featId2: description2 stats2
...
#featIdN: descriptionN statsN
[relevance(u,v) or class1(u,v)] qid:[user u] [featId1]:[value1(u,v)] [featId2]:[value2(u,v)] ... [featIdN]:[valueN(u,v)] #docId=[user v]
...
[relevance(u,v) or class1(u,v)] qid:[user u] [featId1]:[value1(u,v)] [featId2]:[value2(u,v)] ... [featIdN]:[valueN(u,v)] #docId=[user v]
See Also:
LETOR v.4.0
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private boolean comments
    True if comments are allowed, false otherwise.
  • Constructor Summary

    Constructors 
    Constructor Description
    LETORInstanceWriter()
    Constructor.
    LETORInstanceWriter​(boolean comments)
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String write​(Instance<U> instance)
    Obtains an string containing the information for a single instance.
    void write​(java.io.Writer writer, FeatureInformation featInfo)
    Writes the feature information of a file.
    void write​(java.io.Writer writer, Instance<U> instance)
    Writes an individual instance into a file.
    void write​(java.lang.String file, InstanceSet<U> instanceSet)
    Writes a dataset into a file.
    java.lang.String writeFeatureInfo​(FeatureInformation featInfo)
    Obtains an string with all the information about the features of a dataset.
    private java.lang.String writeFeatureInfo​(FeatureInformation featInfo, int i)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • comments

      private final boolean comments
      True if comments are allowed, false otherwise.
  • Constructor Details

    • LETORInstanceWriter

      public LETORInstanceWriter()
      Constructor. Adds comments.
    • LETORInstanceWriter

      public LETORInstanceWriter​(boolean comments)
      Constructor.
      Parameters:
      comments - true to add comments, false otherwise.
  • Method Details

    • write

      public void write​(java.lang.String file, InstanceSet<U> instanceSet) throws java.io.IOException
      Description copied from interface: InstanceSetWriter
      Writes a dataset into a file.
      Specified by:
      write in interface InstanceSetWriter<U>
      Parameters:
      file - the name of the file.
      instanceSet - the instance set to store.
      Throws:
      java.io.IOException - if something fails while writing.
    • writeFeatureInfo

      public java.lang.String writeFeatureInfo​(FeatureInformation featInfo)
      Description copied from interface: InstanceSetWriter
      Obtains an string with all the information about the features of a dataset.
      Specified by:
      writeFeatureInfo in interface InstanceSetWriter<U>
      Parameters:
      featInfo - the feature information.
      Returns:
      a String containing the information about the features.
    • write

      public void write​(java.io.Writer writer, FeatureInformation featInfo) throws java.io.IOException
      Description copied from interface: InstanceSetWriter
      Writes the feature information of a file.
      Specified by:
      write in interface InstanceSetWriter<U>
      Parameters:
      writer - the writer.
      featInfo - feature information to write.
      Throws:
      java.io.IOException - if something fails while writing.
    • write

      public void write​(java.io.Writer writer, Instance<U> instance) throws java.io.IOException
      Description copied from interface: InstanceSetWriter
      Writes an individual instance into a file.
      Specified by:
      write in interface InstanceSetWriter<U>
      Parameters:
      writer - the writer.
      instance - the instance to write.
      Throws:
      java.io.IOException - if something fails while writing.
    • writeFeatureInfo

      private java.lang.String writeFeatureInfo​(FeatureInformation featInfo, int i)
    • write

      public java.lang.String write​(Instance<U> instance)
      Description copied from interface: InstanceSetWriter
      Obtains an string containing the information for a single instance.
      Specified by:
      write in interface InstanceSetWriter<U>
      Parameters:
      instance - the instance.
      Returns:
      an string containing all the necessary information.