facebook graph api - C# - Prevent duplicate retrieval of posts -
i'm rather new , trying create c# program retrieves post facebook using fb api.
i have word count feature checks against negative word dictionary. means display negative word along frequency occurrence.
the problem i'm facing that, want display posts contains negative words. however, if negative word exists 3 times in post, post appear thrice. how solve problem?
below code: (for designer) using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.io; namespace emptrust { public partial class postanalysis : form { dbstatusdl ad; string target_fbid; public postanalysis(string target_fbid) { initializecomponent(); this.target_fbid = target_fbid; ad = new dbstatusdl(); } private void button_displayposts_click(object sender, eventargs e) { int = 1; var dir = new directoryinfo(application.startuppath + "\\dictionary"); //load dictionary debug folder var ed = new matchingwordswithposts(); var rows = ad.loadstatus(target_fbid); //call load status function based on fb_id foreach (fileinfo file in dir.getfiles()) //for loop, loop through files { var dict = file.readalllines(dir.fullname + "\\" + file); foreach (var row in rows) { list<datarow> words = ed.countwordsinstatus(row, dict); // retrieves word dictionary returned function foreach (var word in words) { var item = new listviewitem(new[] { i.tostring() ,word["status_message"].tostring(), word["status_time"].tostring() }); listviewposts.items.add(item); i++; } } } } private void button_back_click(object sender, eventargs e) { this.close(); var abc = new analysispage(target_fbid); abc.show(); } } } (for class) using system; using system.collections.generic; using system.linq; using system.text; using system.text.regularexpressions; using system.data; namespace emptrust { class matchingwordswithposts { public list<datarow> countwordsinstatus(datarow status, string[] dictarray) { list<datarow> statuslist = new list<datarow>(); var words = new dictionary<string, int>(stringcomparer.currentcultureignorecase); // local word dictionary created here foreach (var dictentry in dictarray) { var wordpattern = new regex(@"\w+"); string smalldictentry = dictentry.tolower(); foreach (match match in wordpattern.matches(status["status_message"].tostring())) { if (match.tostring() == smalldictentry) { statuslist.add(status); } } } return statuslist; // returns local word dictionary receiving end } } }
because didn't provide countwordsinstatus()
function, can't know if that's problem. however, looks problem that function continues going through post if has matched 1 such word. fix this, put continue;
(or perhaps break;
, depending on code you're using) after adding post list you're returning. have loop skip next post, , make sure doesn't continue counting words in post has had match.
if post function, should easier understand issue.
Comments
Post a Comment