## 4 Functional Model of the Framework
### Level 2--Traffic Congestion on Main Streets
The algorithm uses IDF*TF, where TF is calculated as shown in Equation (1) \[\text{TF(t)}=\frac{\text{number of times t appears}}{\text{Total number of terms}}\] (1) and IDF is calculated as shown in Equation (2) \[\text{IDF(t)}=\ln(\frac{\text{Total number of docs}}{\text{Number of docs with term t in them}})\] 2. The second approach is based on the DMOZ dictionary [65]. This dictionary is used to calculate the number of words related to the vehicular traffic and if they are larger than a threshold value, the tweet is classified in that category. 3. The third approach is to find the POS for each term in the tweet. We can then measure the similarity with the root of a term for vehicular traffic and its branches in a WORDNET Tree in NLTK [64]. If the result is more than the minimum, the tweet is classified in that category. 4. Finally, an ontology of important words can be built based on previous traffic data so that the most important words that symbolize vehicular traffic are identified. ```
1 Tweets=Get_Tweets();//Preprocessingphase
2 Terms=[];//Initiallistfortemasfterpreprocessingphase
3 ForeachTweetinTweetsDo://Cleaning
4 Tweets=Tweet.Replace(\"SpecialCharacter\",\"\");
5//RepeatthislineaccordingtotheCharacters
6//Tokenizing
7 Tweet_Words=Tweet1.Split(\"\");
8//Converttweettovectorofwordsaccordingtothespacedar
9//Removestopwords
10 StopWorldList=NLTK.Get_Stopwor(Lang=En);
11//PreparethelistofEnglishstopwordsbasedonNLTK
12 ForeachwordinTweet_WordsDo:
13 IfStopWordList.Contain(word)Then
14 Tweet_Words.Remove(WordIndex)
15//Remove
16 Else
17//Steinmer
18 Term=NLTK.PorterStemmer(Tweet_Words(WordIndex));
19 Terms.Add(Term);
20//createvectoroftermsafterpreprocessingphase
21 End~Foreach
22//FirstClassificationPhase
23//Therearethreeoptions
24 Class=ML_Method(Terms);
25 Class=DMOZ_Method(Terms);
26 Class=WORDNET_Method(Terms);
27
28 IfClass=\"Traffic\"Then
29//StartSecondClassificationPhase
30 Keywords=Get_Initial_Rewords_Of_Traffic();
31//Expertwillinitializethislist
32 Count=0;
33 ForeachterminTermsDo:
34 IfKeywords.Contain(term)Then
35//matching
36 Count++;
37 EndForeach
38 Percentage_of_Matching=Count/Terms.Length();
39 IfPercentage_of_Matching>ThresholdThen
40 AddThisTweettoSub_Class_of_Traffic(Class1++)
41//exampleClassforAccident
42 EndForeach
43 IfClass1.Count>Threshold2 Then
44 Send_Alert()
```  
Similarly, the algorithm shown in Listing 3 is used to identify tweets pertaining to vehicular traffic disruption, which is accomplished as follows:  
1. Create a list of terms that symbolize a congestion or disruption of traffic flow in any street or area, such as an accident, police checkpoint, traffic stop, congestion, fire, heavy rain, repair work, and so on. 2. Check if the number of tweets containing one of the above listed terms is more than the minimum, which means that there is such an event in that area or street. Commuters in other areas driving to the event-area will be notified to avoid heading towards it, which will reduce the size of the problem, prevent it from getting worse, and speed up the process of resolving it. ```
1 url=\"Tweets_DataSet.txt\"
2 Inputs=['Feature1','Feature2','Class']
3
4//ClassifyasTrafficorNot
5//Feature1 isIDF,Feature2 isTweetLength
6 dataset=pd.read_csv(url,names=Inputs)//Read
7 print(dataset.describe())//PrintSomeInfoaboutData
8 array=dataset.values//GetAllDataAsTable
9
10//SplittheDatattoFeaturesandClass
11X=array[:,0:2]#Allrowsofcols(startfrom0 to2-1)
11Y=array[:,2]#Allrowsoftched'3
12
13//SplitData80%forTrainingand20%forTesting
14x_train,x_test,y_train,y_test=model_selection.train_test_split(X,Y,test_size=0.2)
15
16//SelecttheMLAlgorithm
17//KNearestNeighbors,VSM,RandomForest,LGRegressionetc.