当前位置: 首页>>代码示例>>C#>>正文


C# Service.BatchedUrlToUid方法代码示例

本文整理汇总了C#中Service.BatchedUrlToUid方法的典型用法代码示例。如果您正苦于以下问题:C# Service.BatchedUrlToUid方法的具体用法?C# Service.BatchedUrlToUid怎么用?C# Service.BatchedUrlToUid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Service的用法示例。


在下文中一共展示了Service.BatchedUrlToUid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main(string[] args)
    {
        bool rfl = false;  // Can LinkDB contain reflexive edges?
        bool dup = false;  // Can LinkDB contain duplicate edges?
        if (args.Length == 4 && string.CompareOrdinal(args[0], "refdup") == 0) {
          rfl = true;
          dup = true;
        } else if (args.Length == 4 && string.CompareOrdinal(args[0], "refnodup") == 0) {
          rfl = true;
          dup = false;
        } else if (args.Length == 4 && string.CompareOrdinal(args[0], "dupnoref") == 0) {
          rfl = false;
          dup = true;
        } else if (args.Length == 4 && string.CompareOrdinal(args[0], "norefdup") == 0) {
          rfl = false;
          dup = false;
        } else {
          Console.Error.WriteLine("Usage: SHS.RegressionTest0 [refdup|refnodup|dupnoref|norefdup] <rawlinks.bin> <servers.txt> <store>");
          System.Environment.Exit(1);
        }
        var sw = System.Diagnostics.Stopwatch.StartNew();
        var smt = new ThriftySetMemberTest();
        var shs = new Service(args[2]).OpenStore(Guid.Parse(args[3]));
        long pageCnt = 0;
        foreach (var fileName in File.ReadAllLines(args[1])) {
          using (var rd = new BinaryReader(new GZipStream(new BufferedStream(new FileStream(fileName, FileMode.Open, FileAccess.Read)), CompressionMode.Decompress))) {
        while (true) {
          try {
            string pageUrl = rd.ReadString();
            long pageUid = shs.UrlToUid(pageUrl);
            string pageUidUrl = shs.UidToUrl(pageUid);
            if (string.CompareOrdinal(pageUrl, pageUidUrl) != 0) {
              Console.Error.WriteLine();
              Console.Error.WriteLine("Regression test failed for page {0} (self-test)", pageCnt);
              Console.Error.WriteLine("Original URL: {0}", pageUrl);
              Console.Error.WriteLine("UrlToUid UID: {0,16:X}", pageUid);
              Console.Error.WriteLine("UidToUrl URL: {0}", pageUidUrl);
              System.Environment.Exit(1);
            }
            int numLinks = rd.ReadInt32();
            var linkUrls = new string[numLinks];
            for (int i = 0; i < numLinks; i++) {
              linkUrls[i] = rd.ReadString();
            }
            if (!smt.ContainsOrAdd(pageUrl)) {
              // Ignore self-links
              var nonReflectiveL = new List<string>();
              for (int i = 0; i < numLinks; i++) {
                if (string.CompareOrdinal(pageUrl, linkUrls[i]) != 0) nonReflectiveL.Add(linkUrls[i]);
              }
              var nonReflectiveA = nonReflectiveL.ToArray();
              var linkUids = shs.BatchedUrlToUid(nonReflectiveA);
              var bwdLinkUids = shs.BatchedGetLinks(linkUids, Dir.Bwd);

              // Backward test first
              for (int i = 0; i < bwdLinkUids.Length; i++) {
                bool found = false;
                for (int j = 0; j < bwdLinkUids[i].Length && !found; j++) {
                  if (pageUid == bwdLinkUids[i][j]) found = true;
                }
                if (!found) {
                  var bwdLinkUrls = shs.BatchedUidToUrl(bwdLinkUids[i]);
                  Console.Error.WriteLine();
                  Console.Error.WriteLine("Regression test failed after {0} seconds for page {1} (bwd test)",
                                          0.001 * sw.ElapsedMilliseconds, pageCnt);
                  Console.Error.WriteLine("pageUrl={0}", pageUrl);
                  Console.Error.WriteLine("linkUrl[{0}]={1}", i, linkUrls[i]);
                  Console.Error.WriteLine("bwdLinkUrls.Length={0}", bwdLinkUrls.Length);
                  for (int j = 0; j < bwdLinkUrls.Length; j++) {
                    Console.Error.WriteLine("bwdLinkUrl[{0}]={1}", j, bwdLinkUrls[j]);
                  }
                  System.Environment.Exit(1);
                }
              }

              // Forward test second
              var fwdLinkUrls = shs.BatchedUidToUrl(shs.GetLinks(pageUid, Dir.Fwd));
              Array.Sort<string>(linkUrls, string.CompareOrdinal);
              Array.Sort<string>(fwdLinkUrls, string.CompareOrdinal);
              int a = 0;
              int b = 0;
              while (a < numLinks && b < fwdLinkUrls.Length) {
                // Skip any reflexive and/or duplicate links, if desired
                while ((!rfl && a < numLinks && string.CompareOrdinal(pageUrl, linkUrls[a]) == 0)
                       || (!dup && a < numLinks - 1 && string.CompareOrdinal(linkUrls[a], linkUrls[a + 1]) == 0)) {
                  a++;
                }
                if (a >= numLinks) {
                  break;
                }
                if (string.CompareOrdinal(linkUrls[a], fwdLinkUrls[b]) != 0) {
                  Console.Error.WriteLine();
                  Console.Error.WriteLine("Regression test failed for page {0} (fwd test1)",
                          pageCnt);
                  Console.Error.WriteLine("raw links file has {0} links:", numLinks);
                  for (int i = 0; i < numLinks; i++) {
                    Console.Error.WriteLine("  link[{0}]={1}", i, linkUrls[i]);
                  }
                  Console.Error.WriteLine("fwd db has {0} links:", fwdLinkUrls.Length);
                  for (int i = 0; i < fwdLinkUrls.Length; i++) {
//.........这里部分代码省略.........
开发者ID:pszmyd,项目名称:SHS,代码行数:101,代码来源:RegressionTest0.cs

示例2: Main

 public static void Main(string[] args)
 {
     var shs = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
     using (var rd = new BinaryReader(new BufferedStream(new FileStream(args[2], FileMode.Open, FileAccess.Read)))) {
       int bs = int.Parse(args[3]);
       int fs = int.Parse(args[4]);
       while (true) {
     try {
       int queryId = rd.ReadInt32();
       int numUrls = rd.ReadInt32();
       var urls = new string[numUrls];
       for (int i = 0; i < numUrls; i++) urls[i] = rd.ReadString();
       var uids = shs.BatchedUrlToUid(urls);
       var tbl = new UidMap(uids);
       var bwdUids = shs.BatchedSampleLinks(tbl, Dir.Bwd, bs, true);
       var fwdUids = shs.BatchedSampleLinks(tbl, Dir.Fwd, fs, true);
       foreach (long[] x in bwdUids) tbl.Add(x);
       foreach (long[] x in fwdUids) tbl.Add(x);
       long[] srcUids = tbl;
       var dstUids = shs.BatchedGetLinks(srcUids, Dir.Fwd);
       int n = dstUids.Length;
       var srcId = new List<int>[n];
       var dstId = new List<int>[n];
       for (int i = 0; i < n; i++) {
         srcId[i] = new List<int>();
         dstId[i] = new List<int>();
       }
       for (int i = 0; i < n; i++) {
         int sid = tbl[srcUids[i]];
         for (int j = 0; j < dstUids[i].Length; j++) {
           int did = tbl[dstUids[i][j]];
           if (did != -1) {
             srcId[sid].Add(did);
             dstId[did].Add(sid);
           }
         }
       }
       int numAuts = 0;
       for (int i = 0; i < n; i++) {
         if (dstId[i].Count > 0) numAuts++;
       }
       double initAut = 1.0 / numAuts;
       var aut = new double[n];
       var tmp = new double[n];
       for (int i = 0; i < n; i++) {
         aut[i] = dstId[i].Count > 0 ? initAut : 0.0;
       }
       for (int k = 0; k < 100; k++) {
         for (int u = 0; u < n; u++) {
           foreach (var id in dstId[u]) {
             tmp[id] += (aut[u] / dstId[u].Count);
           }
           aut[u] = 0.0;
         }
         for (int u = 0; u < n; u++) {
           foreach (var id in srcId[u]) {
             aut[id] += (tmp[u] / srcId[u].Count);
           }
           tmp[u] = 0.0;
         }
       }
       var scores = new double[urls.Length];
       for (int i = 0; i < scores.Length; i++) {
         scores[i] = uids[i] == -1 ? 0.0 : aut[tbl[uids[i]]];
       }
       double bestScore = double.MinValue;
       string bestUrl = null;
       for (int i = 0; i < urls.Length; i++) {
         if (scores[i] > bestScore) {
           bestScore = scores[i];
           bestUrl = urls[i];
         }
       }
       System.Console.Error.WriteLine("{0} {1}", queryId, bestUrl);
     } catch (EndOfStreamException) {
       break;
     }
       }
     }
 }
开发者ID:pszmyd,项目名称:SHS,代码行数:80,代码来源:Salsa.cs


注:本文中的Service.BatchedUrlToUid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。