<commit_before>package com.virdis

import scala.collection.immutable.HashMap

/**
 * Created by sandeep on 11/1/15.
 */

class Graph {

  var noOfEdges = 0

  var adjacencyStore = HashMap.empty[String, Set[String]]

}<commit_msg>logic to calculate avg degree added<commit_after>package com.virdis

import scala.collection.immutable.HashMap

/**
 * Created by sandeep on 11/1/15.
 */

class Graph {

  var adjacencyStore = HashMap.empty[String, Set[String]]

  def processData(data: SecondFeature) = {

    if (data.hashtags.size > 1) {

      val combinationsOfTags: Iterator[Seq[String]] = data.hashtags.combinations(2)

      combinationsOfTags.foreach {
        tags =>
          val from = tags.head
          val to   = tags.tail.head
          addEdge(from, to)
          addEdge(to, from)
      }
    }

  }

  private def addEdge(node1: String, node2: String) = {
    if (adjacencyStore.contains(node1)){
      adjacencyStore = adjacencyStore + ((node1, adjacencyStore(node1) + node2))
    } else {
      adjacencyStore = adjacencyStore + ((node1, Set(node2)))
    }
  }

  def averageDegree: Double = {
    if (adjacencyStore.isEmpty) 0.00
    else {
      var sumOfDegrees: Double = 0.00
      val keysIter: Iterator[String] = adjacencyStore.keysIterator

      while (keysIter.hasNext) {
        sumOfDegrees = sumOfDegrees + adjacencyStore(keysIter.next()).size
      }
      BigDecimal( sumOfDegrees / adjacencyStore.size ).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble
    }
  }
}
{'fraction_non_alphanumeric': 0.1118508655126498, 'fraction_numerical': 0.018641810918774968, 'mean_word_length': 2.9345549738219896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1066490', 'n_tokens_mistral': 531, 'n_tokens_neox': 492, 'n_words': 103}