public AppendEdgeXmlNode ( String vertex1ID, String vertex2ID ) : |
||
vertex1ID | String | |
vertex2ID | String | |
리턴 |
AppendEdgeXmlNode ( GraphMLXmlDocument graphMLXmlDocument, String vertex1ID, String vertex2ID, String relationship ) { Debug.Assert(graphMLXmlDocument != null); Debug.Assert( !String.IsNullOrEmpty(vertex1ID) ); Debug.Assert( !String.IsNullOrEmpty(vertex2ID) ); Debug.Assert( !String.IsNullOrEmpty(relationship) ); XmlNode edgeXmlNode = graphMLXmlDocument.AppendEdgeXmlNode( vertex1ID, vertex2ID); graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeRelationshipID, relationship); return (edgeXmlNode); }
AppendEdgeXmlNode ( GraphMLXmlDocument oGraphMLXmlDocument, String sVertex1ID, String sVertex2ID, String sRelationship ) { Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert( !String.IsNullOrEmpty(sVertex1ID) ); Debug.Assert( !String.IsNullOrEmpty(sVertex2ID) ); Debug.Assert( !String.IsNullOrEmpty(sRelationship) ); AssertValid(); XmlNode oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode( sVertex1ID, sVertex2ID); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, RelationshipID, sRelationship); return (oEdgeXmlNode); }
SaveGraphCore ( IGraph graph, Stream stream ) { Debug.Assert(graph != null); Debug.Assert(stream != null); AssertValid(); GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument( graph.Directedness == GraphDirectedness.Directed); String [] asEdgeAttributeNames = GetAttributeNames(graph, false); String [] asVertexAttributeNames = GetAttributeNames(graph, true); // Define the GraphML-attributes. const String VertexAttributeIDPrefix = "V-"; const String EdgeAttributeIDPrefix = "E-"; foreach (String sVertexAttributeName in asVertexAttributeNames) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, VertexAttributeIDPrefix + sVertexAttributeName, sVertexAttributeName, "string", null); } foreach (String sEdgeAttributeName in asEdgeAttributeNames) { oGraphMLXmlDocument.DefineGraphMLAttribute(true, EdgeAttributeIDPrefix + sEdgeAttributeName, sEdgeAttributeName, "string", null); } // Add the vertices and their GraphML-attribute values. foreach (IVertex oVertex in graph.Vertices) { XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode( oVertex.Name); AppendGraphMLAttributeValues(oVertex, oGraphMLXmlDocument, oVertexXmlNode, asVertexAttributeNames, VertexAttributeIDPrefix); } // Add the edges and their GraphML-attribute values. foreach (IEdge oEdge in graph.Edges) { IVertex [] oVertices = oEdge.Vertices; XmlNode oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode( oVertices[0].Name, oVertices[1].Name); AppendGraphMLAttributeValues(oEdge, oGraphMLXmlDocument, oEdgeXmlNode, asEdgeAttributeNames, EdgeAttributeIDPrefix); } oGraphMLXmlDocument.Save(stream); }
GetRelatedTagsRecursive ( String sTag, WhatToInclude eWhatToInclude, NetworkLevel eNetworkLevel, String sApiKey, Int32 iRecursionLevel, GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<String, XmlNode> oTagDictionary, RequestStatistics oRequestStatistics ) { Debug.Assert( !String.IsNullOrEmpty(sTag) ); Debug.Assert(eNetworkLevel == NetworkLevel.One || eNetworkLevel == NetworkLevel.OnePointFive || eNetworkLevel == NetworkLevel.Two); Debug.Assert( !String.IsNullOrEmpty(sApiKey) ); Debug.Assert(iRecursionLevel == 1 || iRecursionLevel == 2); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oTagDictionary != null); Debug.Assert(oRequestStatistics != null); AssertValid(); /* Here is what this method should do, based on the eNetworkLevel and iRecursionLevel parameters. eNetworkLevel |One | OnePointFive | Two ---|------------------| ------------------| ----------------- i 1 |Add all vertices. | Add all vertices. | Add all vertices. R | | | e |Add all edges. | Add all edges. | Add all edges. c | | | u |Do not recurse. | Recurse. | Recurse. r | | | s ---|------------------|-------------------|------------------ i 2 |Impossible. | Do not add | Add all vertices. o | | vertices. | n | | | L | | Add edges only if | Add all edges. e | | vertices are | v | | already included. | e | | | l | | Do not recurse. | Do not recurse. | | | ---|------------------|-------------------|------------------ */ Boolean bNeedToRecurse = GetNeedToRecurse(eNetworkLevel, iRecursionLevel); Boolean bNeedToAppendVertices = GetNeedToAppendVertices( eNetworkLevel, iRecursionLevel); ReportProgress("Getting tags related to \"" + sTag + "\"."); String sUrl = GetFlickrMethodUrl( "flickr.tags.getRelated", sApiKey, "&tag=" + UrlUtil.EncodeUrlParameter(sTag) ); XmlDocument oXmlDocument; try { oXmlDocument = GetXmlDocument(sUrl, oRequestStatistics); } catch (Exception oException) { // If the exception is not a WebException or XmlException, or if // none of the network has been obtained yet, throw the exception. if (!HttpSocialNetworkUtil.ExceptionIsWebOrXml(oException) || !oGraphMLXmlDocument.HasVertexXmlNode) { throw oException; } return; } // The document consists of a single "tags" node with zero or more // "tag" child nodes. String sOtherTag = null; XmlNodeList oTagNodes = oXmlDocument.DocumentElement.SelectNodes( "tags/tag"); if (oTagNodes.Count > 0) { AppendVertexXmlNode(sTag, oGraphMLXmlDocument, oTagDictionary); } foreach (XmlNode oTagNode in oTagNodes) { sOtherTag = XmlUtil2.SelectRequiredSingleNodeAsString(oTagNode, "text()", null); if (bNeedToAppendVertices) { AppendVertexXmlNode(sOtherTag, oGraphMLXmlDocument, oTagDictionary); } if ( bNeedToAppendVertices || oTagDictionary.ContainsKey(sOtherTag) ) { oGraphMLXmlDocument.AppendEdgeXmlNode(sTag, sOtherTag); } } if (bNeedToRecurse) { foreach (XmlNode oTagNode in oTagNodes) { sOtherTag = XmlUtil2.SelectRequiredSingleNodeAsString(oTagNode, "text()", null); GetRelatedTagsRecursive(sOtherTag, eWhatToInclude, eNetworkLevel, sApiKey, 2, oGraphMLXmlDocument, oTagDictionary, oRequestStatistics); } } }
AddUserUserCommentsEdges ( ref GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<string, Dictionary<string, List<string>>> commentersComments, JSONObject streamPosts, Dictionary<string, Dictionary<string, JSONObject>> attributeValues ) { Dictionary<string, List<string>> postCommenters = new Dictionary<string,List<string>>(); XmlNode oEdgeXmlNode = null; List<string> postsIntersection = new List<string>(); string posts = ""; //Create the Post-Commenter relationship from commenterComments foreach(JSONObject item in streamPosts.Array) { foreach (KeyValuePair<string, Dictionary<string, List<string>>> kvp in commentersComments) { if (kvp.Value.ContainsKey(item.Dictionary["post_id"].String)) { try { postCommenters[item.Dictionary["post_id"].String].Add(kvp.Key); } catch (KeyNotFoundException e) { List<string> tmp = new List<string>(); tmp.Add(kvp.Key); postCommenters.Add(item.Dictionary["post_id"].String, tmp); } } } } //Add Edges foreach (KeyValuePair<string, List<string>> kvp in postCommenters) { for (int i = 0; i < kvp.Value.Count - 1; i++) { for (int j = i + 1; j < kvp.Value.Count; j++) { //Sometimes a commenter or liker can be another fan page and this is not a user if (!usersDisplayName.ContainsKey(kvp.Value[i]) || !usersDisplayName.ContainsKey(kvp.Value[j])) continue; oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode(usersDisplayName[kvp.Value[i]], usersDisplayName[kvp.Value[j]]); postsIntersection = commentersComments[kvp.Value[i]].Keys.Intersect(commentersComments[kvp.Value[j]].Keys).ToList(); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "e_weight", postsIntersection.Count); string[] postsToJoin = (from p in postsIntersection select new { Post = streamPosts.Array.Single(x => x.Dictionary["post_id"].String.Equals(p)).Dictionary["message"].String }).Select(x => x.Post).ToArray(); posts = String.Join("\n\n", postsToJoin); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "post", posts); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "Relationship", "Co-Commenter"); } } } }
AddPostPostLikesEdges ( ref GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<string, List<string>> likersPosts ) { XmlNode oEdgeXmlNode; Dictionary<string, int> postCount = new Dictionary<string, int>(); //Create the post-post network foreach (KeyValuePair<string, List<string>> kvp in likersPosts) { if (kvp.Value.Count > 1) { for (int i = 0; i < kvp.Value.Count - 1; i++) { for (int j = i + 1; j < kvp.Value.Count; j++) { try { postCount[kvp.Value[i] + "-" + kvp.Value[j]]++; } catch (KeyNotFoundException e) { postCount.Add(kvp.Value[i] + "-" + kvp.Value[j], 1); } } } } } //Add edges foreach (KeyValuePair<string, int> kvp in postCount) { string[] postIDs = kvp.Key.Split('-'); oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode(postIDs[0], postIDs[1]); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "e_weight", kvp.Value); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "Relationship", "Post-Post Based on Likes"); } }
AddUserPostLikesEdges ( ref GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<string, List<string>> likersPosts, Dictionary<string, Dictionary<string, JSONObject>> attributeValues ) { XmlNode oEdgeXmlNode = null; foreach (KeyValuePair<string, List<string>> kvp in likersPosts) { foreach (string item in likersPosts[kvp.Key]) { if (!usersDisplayName.ContainsKey(kvp.Key)) continue; oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode(usersDisplayName[kvp.Key], item); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "e_weight", 1); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "Relationship", "User-Post Based on Likes"); } } }
AddUserPostCommentsEdges ( ref GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<string, Dictionary<string, List<string>>> commentersComments, Dictionary<string, Dictionary<string, JSONObject>> attributeValues ) { XmlNode oEdgeXmlNode=null; foreach (KeyValuePair<string, Dictionary<string, List<string>>> kvp in commentersComments) { foreach (KeyValuePair<string, List<string>> kvp2 in commentersComments[kvp.Key]) { if (!usersDisplayName.ContainsKey(kvp.Key)) continue; oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode(usersDisplayName[kvp.Key], kvp2.Key); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "e_weight", kvp2.Value.Count); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "edge_comment", String.Join("\n\n", kvp2.Value.ToArray())); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oEdgeXmlNode, "Relationship", "User-Post Based on Comments"); } } }