Class Data<U extends java.io.Serializable,​I extends java.io.Serializable,​F>

java.lang.Object
es.uam.eps.ir.relison.diffusion.data.Data<U,​I,​F>
Type Parameters:
U - type of the users.
I - type of the information pieces.
F - type of the user and information pieces features.

public class Data<U extends java.io.Serializable,​I extends java.io.Serializable,​F>
extends java.lang.Object
Class that contains the basic information for simulations.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private java.util.Map<java.lang.String,​Index<F>> features
    Feature indexes (stored by the name of the parameter).
    private Graph<U> graph
    The graph in which the simulation will run.
    private java.util.List<java.lang.String> infoPiecesFeatureNames
    List of features related to each information piece
    private java.util.Map<java.lang.String,​Relation<java.lang.Double>> infoPiecesFeatures
    Relation between users and their features (allows identifying the information pieces that share the same feature, as well as the features of the different information pieces).
    private java.util.Map<java.lang.Integer,​Information<I>> informationPieceData
    Additional information for the information pieces.
    private Index<I> informationPieces
    Information pieces index.
    private java.util.HashMap<java.lang.Long,​java.util.HashMap<U,​java.util.Set<I>>> propagatedByTS
    Relation between the timestamps and the pieces propagated by each user.
    private Relation<java.lang.Long> realPropagated
    Map containing the information pieces which have been really propagated by the user.
    private java.util.HashMap<java.lang.Long,​java.util.HashMap<U,​java.util.Set<I>>> realPropagatedByTS
    Relation between the timestamps and the pieces repropagated by each user.
    private java.util.TreeSet<java.lang.Long> timestamps
    Ordered set of timestamps when information pieces where published in real life.
    private java.util.List<java.lang.String> userFeatureNames
    List of features related to each individual user.
    private java.util.Map<java.lang.String,​Relation<java.lang.Double>> userFeatures
    Relation between users and their features (allows identifying the users that share the same feature, as well as the features of the different users).
    private Relation<java.lang.Integer> userInformation
    Relation between users and the propagated information (allows identifying both the information pieces created by a user, and the creator of the information piece.
    private Index<U> users
    User index.
  • Constructor Summary

    Constructors 
    Constructor Description
    Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, Relation<java.lang.Integer> userInformation)
    Simplest constructor.
    Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation)
    Constructor.
    Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation, java.util.Map<java.lang.String,​Index<F>> features, java.util.List<java.lang.String> featureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> featureRel, boolean userfeatures)
    Constructor.
    Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation, java.util.Map<java.lang.String,​Index<F>> features, java.util.List<java.lang.String> userFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> userFeatures, java.util.List<java.lang.String> infoPiecesFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> infoPiecesFeatures)
    Full constructor.
    Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation, java.util.Map<java.lang.String,​Index<F>> features, java.util.List<java.lang.String> userFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> userFeatures, java.util.List<java.lang.String> infoPiecesFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> infoPiecesFeatures, Relation<java.lang.Long> realPropagated)
    Full constructor.
  • Method Summary

    Modifier and Type Method Description
    private void buildTimestampPieces()
    Builds the relationship between timestamps and pairs (user, piece).
    boolean containsFeatureValue​(java.lang.String feature, F value)
    Checks if a feature value exists.
    boolean containsInformationPiece​(I i)
    Indicates if data contains a certain information piece.
    boolean containsUser​(U u)
    Indicates if a user is contained in the data.
    java.lang.String dataSummary()
    Obtains a string containing a summary of the data.
    boolean doesFeatureExist​(java.lang.String feature)
    Checks if a feature is stored in the data.
    java.util.stream.Stream<F> getAllFeatureValues​(java.lang.String parameter)
    Gets all possible values for a certain parameter.
    java.util.stream.Stream<I> getAllInformationPieces()
    Obtain all information pieces.
    java.util.stream.Stream<U> getAllUsers()
    Obtain all users.
    java.util.stream.Stream<U> getCreators​(I piece)
    Obtains the creators of a single information piece.
    Index<F> getFeatureIndex​(java.lang.String param)
    Returns an index for a given parameter.
    Graph<U> getGraph()
    Obtains the graph.
    java.util.List<java.lang.String> getInfoPiecesFeatureNames()
    Obtains the names of the information piece features.
    java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<F>> getInfoPiecesFeatures​(I info, java.lang.String param)
    Obtains the features for a single information piece.
    Information<I> getInformation​(I piece)
    Obtains the extended information of an information piece
    Index<I> getInformationPiecesIndex()
    Obtains an index for the different information pieces.
    java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<I>> getInformationPiecesWithFeature​(java.lang.String feature, F value)
    Obtains all information pieces with a certain feature value.
    java.util.stream.Stream<I> getPieces​(U user)
    Obtains the information pieces created by a user.
    java.util.stream.Stream<I> getPiecesByTimestamp​(long timestamp, U user)
    Obtains the list of pieces that a user has propagated in a given time.
    java.util.stream.Stream<I> getRealPropagatedPieces​(U user)
    Given a user, obtains the set of information pieces repropagated in a real scenario.
    java.util.stream.Stream<Tuple2ol<I>> getRealPropagatedPiecesWithTimestamp​(U user)
    Given a user, obtains the set of information pieces repropagated in a real scenario.
    long getRealPropagatedTimestamp​(U user, I info)
    Obtains the timestamp for an information piece.
    java.util.stream.Stream<U> getRealPropagatedUsers​(I piece)
    Given an information piece, obtains the set of users that repropagated them in a real scenario.
    java.util.stream.Stream<I> getRealPropPiecesByTimestamp​(long timestamp, U user)
    Obtains the list of pieces which have been repropagated by a user at a given time.
    java.util.stream.Stream<U> getRealPropUsersByTimestamp​(long timestamp)
    Obtains the list of users which have repropagated pieces at a given time.
    long getTimestamp​(I info)
    Obtains the timestamp for an information piece.
    java.util.TreeSet<java.lang.Long> getTimestamps()
    Obtains the list of timestamps.
    java.util.List<java.lang.String> getUserFeatureNames()
    Obtains the names of the user features.
    java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<F>> getUserFeatures​(U user, java.lang.String param)
    Obtains the features for a single user.
    Index<U> getUserIndex()
    Obtains a user index for creating relations.
    java.util.stream.Stream<U> getUsersByTimestamp​(long timestamp)
    Obtains the list of users which have propagated pieces at a given time.
    java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<U>> getUsersWithFeature​(java.lang.String feature, F value)
    Obtains all users with a certain feature value.
    boolean isInfoPieceFeature​(java.lang.String feature)
    Checks if a feature exists, and it is an information piece feature.
    boolean isRealRepropagatedPiece​(U user, I piece)
    Checks if a user repropagated or not an information piece.
    boolean isUserFeature​(java.lang.String feature)
    Checks if a feature exists, and it is a user feature.
    int numFeatureValues​(java.lang.String parameter)
    Gets the number of possible values for a certain parameter.
    int numInformationPieces()
    Obtains the number of information pieces.
    int numUsers()
    Obtain the number of users in the simulation.

    Methods inherited from class java.lang.Object

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

    • users

      private final Index<U extends java.io.Serializable> users
      User index.
    • informationPieces

      private final Index<I extends java.io.Serializable> informationPieces
      Information pieces index.
    • informationPieceData

      private final java.util.Map<java.lang.Integer,​Information<I extends java.io.Serializable>> informationPieceData
      Additional information for the information pieces.
    • features

      private final java.util.Map<java.lang.String,​Index<F>> features
      Feature indexes (stored by the name of the parameter).
    • userInformation

      private final Relation<java.lang.Integer> userInformation
      Relation between users and the propagated information (allows identifying both the information pieces created by a user, and the creator of the information piece.
    • graph

      private final Graph<U extends java.io.Serializable> graph
      The graph in which the simulation will run.
    • userFeatureNames

      private final java.util.List<java.lang.String> userFeatureNames
      List of features related to each individual user.
    • infoPiecesFeatureNames

      private final java.util.List<java.lang.String> infoPiecesFeatureNames
      List of features related to each information piece
    • userFeatures

      private final java.util.Map<java.lang.String,​Relation<java.lang.Double>> userFeatures
      Relation between users and their features (allows identifying the users that share the same feature, as well as the features of the different users).
    • infoPiecesFeatures

      private final java.util.Map<java.lang.String,​Relation<java.lang.Double>> infoPiecesFeatures
      Relation between users and their features (allows identifying the information pieces that share the same feature, as well as the features of the different information pieces).
    • realPropagated

      private final Relation<java.lang.Long> realPropagated
      Map containing the information pieces which have been really propagated by the user.
    • timestamps

      private java.util.TreeSet<java.lang.Long> timestamps
      Ordered set of timestamps when information pieces where published in real life.
    • propagatedByTS

      private final java.util.HashMap<java.lang.Long,​java.util.HashMap<U extends java.io.Serializable,​java.util.Set<I extends java.io.Serializable>>> propagatedByTS
      Relation between the timestamps and the pieces propagated by each user.
    • realPropagatedByTS

      private final java.util.HashMap<java.lang.Long,​java.util.HashMap<U extends java.io.Serializable,​java.util.Set<I extends java.io.Serializable>>> realPropagatedByTS
      Relation between the timestamps and the pieces repropagated by each user.
  • Constructor Details

    • Data

      public Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, Relation<java.lang.Integer> userInformation)
      Simplest constructor. There is no additional information for information pieces, nor features.
      Parameters:
      graph - the social network graph.
      users - the user index.
      informationPieces - information pieces index.
      userInformation - relation between users and information pieces.
    • Data

      public Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation)
      Constructor. There is no additional information for information pieces, nor features.
      Parameters:
      graph - the social network graph.
      users - the user index.
      informationPieces - information pieces index.
      informationData - detailed information about the information pieces.
      userInformation - relation between users and information pieces.
    • Data

      public Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation, java.util.Map<java.lang.String,​Index<F>> features, java.util.List<java.lang.String> featureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> featureRel, boolean userfeatures)
      Constructor. Only user / information pieces features.
      Parameters:
      graph - the social network graph.
      users - the user index.
      informationPieces - information pieces index.
      informationData - detailed information about the information pieces.
      userInformation - relation between users and information pieces.
      features - indexes for the different features.
      featureNames - the names of the user/pieces features.
      featureRel - relation between users/pieces and their features.
      userfeatures - true if features are related to users, false if they are related to information pieces.
    • Data

      public Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation, java.util.Map<java.lang.String,​Index<F>> features, java.util.List<java.lang.String> userFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> userFeatures, java.util.List<java.lang.String> infoPiecesFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> infoPiecesFeatures)
      Full constructor.
      Parameters:
      graph - the social network graph.
      users - the user index.
      informationPieces - information pieces index.
      informationData - detailed information about the information pieces.
      userInformation - relation between users and information pieces.
      features - indexes for the different features.
      userFeatureNames - the names of the user features.
      userFeatures - relation between users and their features.
      infoPiecesFeatureNames - the name for information pieces features.
      infoPiecesFeatures - relation between information pieces and their features.
    • Data

      public Data​(Graph<U> graph, Index<U> users, Index<I> informationPieces, java.util.Map<java.lang.Integer,​Information<I>> informationData, Relation<java.lang.Integer> userInformation, java.util.Map<java.lang.String,​Index<F>> features, java.util.List<java.lang.String> userFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> userFeatures, java.util.List<java.lang.String> infoPiecesFeatureNames, java.util.Map<java.lang.String,​Relation<java.lang.Double>> infoPiecesFeatures, Relation<java.lang.Long> realPropagated)
      Full constructor.
      Parameters:
      graph - the social network graph.
      users - the user index.
      informationPieces - information pieces index.
      informationData - detailed information about the information pieces.
      userInformation - relation between users and information pieces.
      features - indexes for the different features.
      userFeatureNames - the names of the user features.
      userFeatures - relation between users and their features.
      infoPiecesFeatureNames - the name for information pieces features.
      infoPiecesFeatures - relation between information pieces and their features.
      realPropagated - relation indicating which information pieces were repropagated in real scenario.
  • Method Details

    • buildTimestampPieces

      private void buildTimestampPieces()
      Builds the relationship between timestamps and pairs (user, piece).
    • getAllUsers

      public java.util.stream.Stream<U> getAllUsers()
      Obtain all users.
      Returns:
      a stream containing all users.
    • numUsers

      public int numUsers()
      Obtain the number of users in the simulation.
      Returns:
      the number of users.
    • getUserIndex

      public Index<U> getUserIndex()
      Obtains a user index for creating relations.
      Returns:
      the user index.
    • getAllInformationPieces

      public java.util.stream.Stream<I> getAllInformationPieces()
      Obtain all information pieces.
      Returns:
      a stream containing all information pieces.
    • numInformationPieces

      public int numInformationPieces()
      Obtains the number of information pieces.
      Returns:
      the number of information pieces.
    • getInformationPiecesIndex

      public Index<I> getInformationPiecesIndex()
      Obtains an index for the different information pieces.
      Returns:
      the information pieces index.
    • getInformation

      public Information<I> getInformation​(I piece)
      Obtains the extended information of an information piece
      Parameters:
      piece - the information piece.
      Returns:
      the extended information if the piece exists, null if it does not.
    • getCreators

      public java.util.stream.Stream<U> getCreators​(I piece)
      Obtains the creators of a single information piece.
      Parameters:
      piece - the piece.
      Returns:
      a stream of creators, empty if there are none.
    • getPieces

      public java.util.stream.Stream<I> getPieces​(U user)
      Obtains the information pieces created by a user.
      Parameters:
      user - the user.
      Returns:
      a stream of information pieces, empty if there are none.
    • getTimestamp

      public long getTimestamp​(I info)
      Obtains the timestamp for an information piece.
      Parameters:
      info - the information piece.
      Returns:
      the timestamp in case it exists, -1 if it does not.
    • getGraph

      public Graph<U> getGraph()
      Obtains the graph.
      Returns:
      the graph.
    • getUserFeatures

      public java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<F>> getUserFeatures​(U user, java.lang.String param)
      Obtains the features for a single user.
      Parameters:
      user - the user.
      param - the parameter.
      Returns:
      a stream of pairs (parameter,value), empty if there are none.
    • getInfoPiecesFeatures

      public java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<F>> getInfoPiecesFeatures​(I info, java.lang.String param)
      Obtains the features for a single information piece.
      Parameters:
      info - the information piece.
      param - the parameter.
      Returns:
      a stream of pairs (parameter,value), empty if there are none.
    • getAllFeatureValues

      public java.util.stream.Stream<F> getAllFeatureValues​(java.lang.String parameter)
      Gets all possible values for a certain parameter.
      Parameters:
      parameter - the parameter name.
      Returns:
      a stream containing all the possible values if the parameter exists, an empty stream if it does not.
    • numFeatureValues

      public int numFeatureValues​(java.lang.String parameter)
      Gets the number of possible values for a certain parameter.
      Parameters:
      parameter - the parameter name.
      Returns:
      the number of possible features if the parameter exists, 0 if it does not.
    • getFeatureIndex

      public Index<F> getFeatureIndex​(java.lang.String param)
      Returns an index for a given parameter.
      Parameters:
      param - the parameter name.
      Returns:
      the index if it exists, null if it does not.
    • containsUser

      public boolean containsUser​(U u)
      Indicates if a user is contained in the data.
      Parameters:
      u - the user.
      Returns:
      true if the user is contained in the data, false if it is not.
    • containsInformationPiece

      public boolean containsInformationPiece​(I i)
      Indicates if data contains a certain information piece.
      Parameters:
      i - the information piece.
      Returns:
      true if the user is contained in the data, false if it is not.
    • doesFeatureExist

      public boolean doesFeatureExist​(java.lang.String feature)
      Checks if a feature is stored in the data.
      Parameters:
      feature - the feature name.
      Returns:
      true if the feature exists, false otherwise.
    • isUserFeature

      public boolean isUserFeature​(java.lang.String feature)
      Checks if a feature exists, and it is a user feature.
      Parameters:
      feature - the feature name.
      Returns:
      true if the feature exists, false otherwise.
    • isInfoPieceFeature

      public boolean isInfoPieceFeature​(java.lang.String feature)
      Checks if a feature exists, and it is an information piece feature.
      Parameters:
      feature - the feature name.
      Returns:
      true if the feature exists, false otherwise.
    • getUserFeatureNames

      public java.util.List<java.lang.String> getUserFeatureNames()
      Obtains the names of the user features.
      Returns:
      a list containing the user features.
    • getInfoPiecesFeatureNames

      public java.util.List<java.lang.String> getInfoPiecesFeatureNames()
      Obtains the names of the information piece features.
      Returns:
      a list containing the information piece features.
    • containsFeatureValue

      public boolean containsFeatureValue​(java.lang.String feature, F value)
      Checks if a feature value exists.
      Parameters:
      feature - the feature name.
      value - the feature value we want to check.
      Returns:
      true if the value exists, false otherwise.
    • getUsersWithFeature

      public java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<U>> getUsersWithFeature​(java.lang.String feature, F value)
      Obtains all users with a certain feature value.
      Parameters:
      feature - the name of the feature.
      value - the value of the feature.
      Returns:
      a stream containing the different pairs (user, value) that are represented by the value parameter.
    • getInformationPiecesWithFeature

      public java.util.stream.Stream<org.ranksys.core.util.tuples.Tuple2od<I>> getInformationPiecesWithFeature​(java.lang.String feature, F value)
      Obtains all information pieces with a certain feature value.
      Parameters:
      feature - the name of the feature.
      value - the value of the feature.
      Returns:
      a stream containing the different pairs (infopiece, value) that are represented by the value parameter.
    • getRealPropagatedUsers

      public java.util.stream.Stream<U> getRealPropagatedUsers​(I piece)
      Given an information piece, obtains the set of users that repropagated them in a real scenario.
      Parameters:
      piece - the information piece.
      Returns:
      the stream of users that repropagated the piece.
    • getRealPropagatedPieces

      public java.util.stream.Stream<I> getRealPropagatedPieces​(U user)
      Given a user, obtains the set of information pieces repropagated in a real scenario.
      Parameters:
      user - the user.
      Returns:
      the stream of pieces repropagated by the user.
    • getRealPropagatedPiecesWithTimestamp

      public java.util.stream.Stream<Tuple2ol<I>> getRealPropagatedPiecesWithTimestamp​(U user)
      Given a user, obtains the set of information pieces repropagated in a real scenario.
      Parameters:
      user - the user.
      Returns:
      the stream of pieces repropagated by the user and their timestamps.
    • isRealRepropagatedPiece

      public boolean isRealRepropagatedPiece​(U user, I piece)
      Checks if a user repropagated or not an information piece.
      Parameters:
      user - the user.
      piece - the piece.
      Returns:
      true if the user repropagated the piece, false if he/she did not.
    • getRealPropagatedTimestamp

      public long getRealPropagatedTimestamp​(U user, I info)
      Obtains the timestamp for an information piece.
      Parameters:
      user - the user.
      info - the piece.
      Returns:
      the timestamp if the user repropagated the piece, -1 if he/she did not.
    • getTimestamps

      public java.util.TreeSet<java.lang.Long> getTimestamps()
      Obtains the list of timestamps.
      Returns:
      the list of timestamps.
    • getPiecesByTimestamp

      public java.util.stream.Stream<I> getPiecesByTimestamp​(long timestamp, U user)
      Obtains the list of pieces that a user has propagated in a given time.
      Parameters:
      timestamp - the timestamp.
      user - the user.
      Returns:
      an stream containing the pieces propagated by the user at the given time.
    • getRealPropPiecesByTimestamp

      public java.util.stream.Stream<I> getRealPropPiecesByTimestamp​(long timestamp, U user)
      Obtains the list of pieces which have been repropagated by a user at a given time.
      Parameters:
      timestamp - the timestamp.
      user - the user.
      Returns:
      an stream containing the pieces repropagated by the user at the given time.
    • getUsersByTimestamp

      public java.util.stream.Stream<U> getUsersByTimestamp​(long timestamp)
      Obtains the list of users which have propagated pieces at a given time.
      Parameters:
      timestamp - the timestamp.
      Returns:
      a stream containing all users which have propagated information at the given time.
    • getRealPropUsersByTimestamp

      public java.util.stream.Stream<U> getRealPropUsersByTimestamp​(long timestamp)
      Obtains the list of users which have repropagated pieces at a given time.
      Parameters:
      timestamp - the timestamp.
      Returns:
      a stream containing all users which have repropagated information at the given time.
    • dataSummary

      public java.lang.String dataSummary()
      Obtains a string containing a summary of the data.
      Returns:
      The summary of the data.