virtual Intelligence
Wednesday, December 5, 2007
temp Explaination
namespace testingWebLinks
{
class Program
{
static void Main(string[] args)
{
string line;
Dictionary
<string,string> dictionaryOutLinks = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ out links ဘယ္ႏွခုရိွလည္း ကို သိမ္းမွာ။
Dictionary<string,string> dictionaryInLinks = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ in links ဘယ္ႏွခုရိွလည္း ကို သိမ္းမွာ။
Dictionary<string,string> dictionaryOutPages = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ ဘယ္ out page ေတြဆီိကို ထြက္သြားတာလည္းကို သိမ္းမွာ။
Dictionary<string,string> dictionaryInPages = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ ဘယ္ in page ေတြက ၀င္လာတာလည္းကို သိမ္းမွာ။
dictionaryInLinks.Clear();
dictionaryOutLinks.Clear();
dictionaryInPages.Clear();
dictionaryOutPages.Clear();
ဒါကေတာ့ စစခ်င္း clear လုပ္တာပါ။ အေရးမၾကီးပါ။
// Read the file and display it line by line.
String visitedString = "Visited:";
သူက ငါတို ့ဖတ္မဲ့ link က visited link ဟုတ္လား မဟုတ္လားကို စစ္ဖို ့။
String curVisitStr = String.Empty;
သူကေတာ့ လက္ရိွ visited link ကို သိမ္းထားဖို ့ (program အရ လိုေနလို ့ပါ။ေလာဂ်စ္အရ အေရးမၾကီး)။
Int32 inCounter = 0;
in links စုစု ေပါင္း
Int32 outCounter = 0;
out link စုစုးေပါင္း
Boolean isInVisited = false;
သူက မလို ပါဘူး။
System.IO.StreamReader file = new System.IO.StreamReader("C:\\Documents and Settings\\nhyan\\Desktop\\weblinks.txt");
ငါတို ့.. web log file ကို ဖတ္လိုက္တာ။
try
{
while ((line = file.ReadLine()) != null)
တစ္ေၾကာင္းခ်င္းloop ပတ္တယ္။
{
if (line.StartsWith(visitedString))
ဖတ္လိုက္တဲ့ link က visited နဲ ့ စတာလားကို စစ္
{
if (outCounter != 0)
ပထမဆံုး visited link လား ေနာက္မွ ေတြ ့တဲ့ visited link လားစစ္
{
dictionaryOutLinks[curVisitStr.Trim()] = outCounter.ToString();
outCounter = 0; isInVisited = false;
}
dictionaryOutLinks.Add(line.Trim(), outCounter.ToString());
dictionaryOutPages.Add(line.Trim(), String.Empty);
ပထမဆံုး visited link ကို သိမ္းတယ္။သူရဲ ့ counter က ေလာေလာဆယ္ 0 ေပါ့။
curVisitStr = line.Trim();
curVisitStr ထဲကို လက္ရိွ link ကို ထည့္တယ္။
isInVisited = true;
ဒါကမလို
}
else
ဖတ္လိုက္တဲ့ link က visited နဲ ့ စတာမဟုတ္ဘူးဆိုရင္
{
if (isInVisited == true)
ဒါလည္း မလို
{
if (!dictionaryInLinks.ContainsKey(line.Trim()))
In links dictionary ထည္းမွာ လက္ရိွ link ဟာ ရိွပီးလား ကို စစ္( မ၇ိွေသးဘူးဆိုရင္)
{
inCounter++;
in coutner ကို ၁ တိုး
dictionaryInLinks.Add(line.Trim(), inCounter.ToString());
In links dictionary ကို လက္ရိွ Link က key၊ in counter က value အၿဖစ္ သိမ္း
outCounter++;
out counter ကိုလည္း ၁ တိုး.. ဒါက တစ္ေၾကာင္းဖတ္တိုင္း တိုးရမွာေလ ။ အခုက out link ကို ဖတ္ေနတာ
dictionaryInPages.Add(line.Trim(), curVisitStr);
in page dictionary ကို လည္း လက္၇ွိဖတ္ေနတဲ့ link ရယ္၊ အေပၚက visited link ၇ယ္ကို key value အၿဖစ္သိမ္း
}
else
In links dictionary ထည္းမွာ လက္ရိွ link ဟာ ရိွပီးလား ကို စစ္( ရိွတယ္ဆိုရင္) ရိွပီးသားကို update လုပ္ရမယ္ေလ အသစ္ထည့္လို ့မရေတာ့ဘူး
{
String tempValue = String.Empty;
String tempString = String.Empty;
// in link dictionar ကို key လက္၇ိွ link ေပးပီ ေတာ့ value ကို ထုတ္ယူ
dictionaryInLinks.TryGetValue(line.Trim(), out tempValue);
inCounter = Convert.ToInt32(tempValue);
inCounter++;
အဲဒီ value ကို ၁ တိုး
dictionaryInLinks[line.Trim()] = inCounter.ToString();
ၿပန္ပီးေတာ့ ထည့္
//dictionaryInLinks.Remove(line);
//dictionaryInLinks.Add(line, inCounter);
//တဆက္တည္း in page ပါ update လုပ္သြား
dictionaryInPages.TryGetValue(line.Trim(), out tempValue);
လက္ရိွ link ကို key အၿဖစ္ ေပးပီးေတာ့ထုတ္ယူ
tempString = tempValue.Trim() + "::" + curVisitStr.Trim();
value ကို update လုပ္
dictionaryInPages[line.Trim()] = tempString;
ၿပန္ထည့္
outCounter++;
ဒါကေတာ့ out counter ကို ၁ တိုးရမယ္ေလ။
}
String tempOutValue = String.Empty;
dictionaryOutPages.TryGetValue(curVisitStr.Trim(), out tempOutValue);
tempOutValue = tempOutValue + "::" + line.Trim();
dictionaryInLinks[curVisitStr.Trim()] = tempOutValue;
}
}
}
ဒီေအာက္ပိုင္းက.. dictionary ထည္းမွာ သိမ္းထားတာေတြကို txtဖိုင္မွာ ၿပန္၇ိုက္ထုတ္တာ။
Int32 i = 0;
TextWriter twOutLink = new StreamWriter("C:\\Documents and Settings\\nhyan\\Desktop\\outLinks.txt");
foreach (KeyValuePair
kvp in dictionaryOutLinks)
{
if (i == 0)
{
// write a line of text to the file
twOutLink.Write("OUT LINKS");
twOutLink.WriteLine("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t PAGES");
i = 1;
}
twOutLink.WriteLine("{0} \t\t\t\t {1}",
kvp.Key, kvp.Value);
}
// close the stream
twOutLink.Close();
Int32 j = 0;
TextWriter twInLink = new StreamWriter("C:\\Documents and Settings\\nhyan\\Desktop\\inLinks.txt");
foreach (KeyValuePair
kvp in dictionaryInLinks)
{
if (j == 0)
{
// write a line of text to the file
twInLink.Write("OUT LINKS");
twInLink.WriteLine("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t PAGES");
j = 1;
}
twInLink.WriteLine("{0} \t\t\t\t {1}",
kvp.Key, kvp.Value);
}
// close the stream
twInLink.Close();
}
catch (KeyNotFoundException exp)
{
Console.Write(exp.ToString());
}
// Suspend the screen.
Console.ReadLine();
}
}
}
0 comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
C++
(2)
javascript
(6)
javascript_array_obj
(1)
javascript_array_statement
(1)
javascript_date_obj
(1)
javascript_method
(1)
javascript_obj
(2)
javascript_statement
(1)
mobile troubleshooting
(2)
Regular Expression
(2)
WCF
(1)
XML
(4)
►
2008
(5)
►
October
(1)
for … in Statement ဒီ for.. in ကို javascript arr...
►
September
(3)
Array တစ္ခု တည္ေဆာက္ၿခင္း
Fundamental concept of WCF (Microsoft Window Comm...
Javascript toLocaleString() Method အဓိပၸါယ္ဖြင့္ဆိ...
►
August
(1)
XML Schemas (XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ...
▼
2007
(18)
▼
December
(3)
XML Schemas (XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ...
temp Explaination
XML Schemas (XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ...
►
November
(1)
XML Schemas (XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ...
►
October
(1)
XML Schemas (XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ...
►
August
(5)
Scope in JavaScript (part 4) (JavaScript ????????...
Scope in JavaScript (part 3) (JavaScript မွာရိွေသ...
Scope in JavaScript (part 2) (JavaScript မွာရိွေသ...
Scope in JavaScript (part 1) (JavaScript မွာရိွေသ...
ေရးသူ - သန္ ့ေဇာ္မင္း ေန ့စြဲ - july 31,2007 ----...
►
July
(5)
Mobile Device Troubleshooting 2 Unable to Debug/Tr...
ေရးသူ - သန္ ့ေဇာ္မင္း ေန ့စြဲ - july 26,2007 ----...
Mobile Device Troubleshooting 1 SQL Query Analyzer...
Regular Expression (စကာလံုးအစုပံုစံ) စကား...
စကားလံုးအစုပံုစံ ၀ါက် (Regular Expression Syntax) ...
►
June
(3)
Download ရႏိုင္ေသာ ေနရာမ်ား
ကၽြန္ေတာ္၊ ကၽြန္မ တို ့သည္..
Best Links