Class Trie

  • All Implemented Interfaces:
    java.lang.Comparable<Trie>

    public class Trie
    extends java.lang.Object
    implements java.lang.Comparable<Trie>
    Class that implement a trie structure. A trie is composed of a list of nodes children that are also the beginning of other trie structure. Those nodes are composed of both a ItemAstractionPair object and a Trie, where the children appear. The current trie is referring to a pattern that can be obtained from the root until this one, passing by the different nodes in the way that are ancestors of the current trie. We do not keep any trace of the parent nodes since the whole trie will be run at the end of the algorithm, just before applying the postprocessing step to remove the remaining non-closed frequent patterns. Besides, in a trie we keep some information relative to that pattern that is referred, such as the sequences where the pattern appears, its support, and some other information used in the key generation of the pruning methods. Copyright Antonio Gomariz PeƱalver 2013 This file is part of the SPMF DATA MINING SOFTWARE (http://www.philippe-fournier-viger.com/spmf). SPMF is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SPMF is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SPMF. If not, see .
    Author:
    agomariz
    • Constructor Summary

      Constructors 
      Constructor Description
      Trie()
      Standard constructor of a Trie.
      Trie​(java.util.List<TrieNode> nodes)
      Constructor of a Trie by means of a list of NodeTrie.
      Trie​(java.util.List<TrieNode> nodes, IDList idList)
      Constructor of a Trie by means of a list of NodeTrie and the IdList of the pattern associated to the trie.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Trie t)
      It compares this trie with another
      java.util.BitSet getAppearingIn()
      It returns the list of sequences Ids where the pattern referred by the Trie appears.
      Trie getChild​(int index)
      It obtain its ith trie child
      IDList getIdList()
      It gets the IdList of the pattern associated to the trie
      TrieNode getNode​(int index)
      It gets the whole TrieNode of the ith child
      java.util.List<TrieNode> getNodes()
      It gets the list of nodes associated with the Trie
      ItemAbstractionPair getPair​(int index)
      It gets the pair of the ith child
      int getSumIdSequences()
      It gets the sum of the sequence identifiers of the sequences where the pattern, referred by the Trie, appears
      int getSupport()
      It gets the support of the pattern referred by the Trie.
      int levelSize()
      It returns the number of children that a Trie has
      int levelSize_i()  
      void mergeWithTrie​(TrieNode trie)
      It merges a trie with another one, inserting the TrieNode given as parameter in the list of node associated with the current Trie.
      void mergeWithTrie_i​(TrieNode trie)  
      java.util.List<java.util.Map.Entry<Pattern,​Trie>> preorderTraversal​(Pattern p)
      It makes a pre-order traversal from the Trie.
      boolean remove​(int index)
      It removes the ith child of the Trie.
      void removeAll()
      It removes all its descendands tries and then the Trie itself.
      void setAppearingIn​(java.util.BitSet appearingIn)
      It updates the list of sequences Ids where the pattern referred by the Trie appears
      void setChild​(int index, Trie child)
      It set a child to the Trie given as parameter
      void setIdList​(IDList idList)
      It updates the value of the IdList of the pattern associated to the trie
      void setNode​(int index, TrieNode node)
      It updates the whole TrieNode of the ith child
      void setNodes​(java.util.List<TrieNode> nodes)
      It updates the list of nodes associated with the Trie
      void setSumIdSequences​(int sumIdSequences)
      It updates the sum of the sequence identifiers of the sequences where the pattern, referred by the Trie, appears
      void setSupport​(int support)
      It updates the support of the pattern referred by the Trie
      void sort()
      It sorts the children by lexicographic order (given by their pair values)
      java.lang.String toString()
      Get a string representation of this Trie
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Trie

        public Trie​(java.util.List<TrieNode> nodes,
                    IDList idList)
        Constructor of a Trie by means of a list of NodeTrie and the IdList of the pattern associated to the trie.
        Parameters:
        nodes - List of nodes with which we want to initialize the Trie
        idList - IdList of the pattern associated to the trie
      • Trie

        public Trie​(java.util.List<TrieNode> nodes)
        Constructor of a Trie by means of a list of NodeTrie.
        Parameters:
        nodes - List of nodes with which we want to initialize the Trie
      • Trie

        public Trie()
        Standard constructor of a Trie. It sets the list of nodes to empty.
    • Method Detail

      • mergeWithTrie_i

        public void mergeWithTrie_i​(TrieNode trie)
      • levelSize_i

        public int levelSize_i()
      • getChild

        public Trie getChild​(int index)
        It obtain its ith trie child
        Parameters:
        index - Child index in which we are interested
        Returns:
        the trie
      • setChild

        public void setChild​(int index,
                             Trie child)
        It set a child to the Trie given as parameter
        Parameters:
        index - Child index in which we are interested
        child - Trie that we want to insert
      • getIdList

        public IDList getIdList()
        It gets the IdList of the pattern associated to the trie
        Returns:
        the idlist
      • setIdList

        public void setIdList​(IDList idList)
        It updates the value of the IdList of the pattern associated to the trie
        Parameters:
        idList -
      • getNodes

        public java.util.List<TrieNode> getNodes()
        It gets the list of nodes associated with the Trie
        Returns:
        the list of trie nodes
      • setNodes

        public void setNodes​(java.util.List<TrieNode> nodes)
        It updates the list of nodes associated with the Trie
        Parameters:
        nodes -
      • remove

        public boolean remove​(int index)
        It removes the ith child of the Trie.
        Parameters:
        index - Child index in which we are interested
        Returns:
        true if the item was removed, otherwise it means that the index is outside the bounds of the trie
      • getPair

        public ItemAbstractionPair getPair​(int index)
        It gets the pair of the ith child
        Parameters:
        index - Child index in which we are interested
        Returns:
        the pair
      • getNode

        public TrieNode getNode​(int index)
        It gets the whole TrieNode of the ith child
        Parameters:
        index - Child index in which we are interested
        Returns:
        the trie node
      • setNode

        public void setNode​(int index,
                            TrieNode node)
        It updates the whole TrieNode of the ith child
        Parameters:
        index - Child index in which we are interested
        node -
      • levelSize

        public int levelSize()
        It returns the number of children that a Trie has
        Returns:
        the number of children
      • removeAll

        public void removeAll()
        It removes all its descendands tries and then the Trie itself.
      • mergeWithTrie

        public void mergeWithTrie​(TrieNode trie)
        It merges a trie with another one, inserting the TrieNode given as parameter in the list of node associated with the current Trie.
        Parameters:
        trie -
      • sort

        public void sort()
        It sorts the children by lexicographic order (given by their pair values)
      • getAppearingIn

        public java.util.BitSet getAppearingIn()
        It returns the list of sequences Ids where the pattern referred by the Trie appears.
        Returns:
        the list of sequence IDs as a bitset
      • setAppearingIn

        public void setAppearingIn​(java.util.BitSet appearingIn)
        It updates the list of sequences Ids where the pattern referred by the Trie appears
        Parameters:
        appearingIn - The list of sequence Ids to update
      • toString

        public java.lang.String toString()
        Get a string representation of this Trie
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • getSupport

        public int getSupport()
        It gets the support of the pattern referred by the Trie.
        Returns:
        the support
      • setSupport

        public void setSupport​(int support)
        It updates the support of the pattern referred by the Trie
        Parameters:
        support -
      • getSumIdSequences

        public int getSumIdSequences()
        It gets the sum of the sequence identifiers of the sequences where the pattern, referred by the Trie, appears
        Returns:
        the sum
      • setSumIdSequences

        public void setSumIdSequences​(int sumIdSequences)
        It updates the sum of the sequence identifiers of the sequences where the pattern, referred by the Trie, appears
        Parameters:
        sumIdSequences - Value of the sum of sequence identifiers to update
      • preorderTraversal

        public java.util.List<java.util.Map.Entry<Pattern,​Trie>> preorderTraversal​(Pattern p)
        It makes a pre-order traversal from the Trie. The result is concatenate to the prefix pattern given as parameter
        Parameters:
        p - Prefix pattern
        Returns:
        a list of entries
      • compareTo

        public int compareTo​(Trie t)
        It compares this trie with another
        Specified by:
        compareTo in interface java.lang.Comparable<Trie>
        Parameters:
        t - the other trie
        Returns:
        0 if equal, -1 if smaller, otherwise 1