首页 文章 精选 留言 我的

精选列表

搜索[正则过滤],共10000篇文章
优秀的个人博客,低调大师

MapReduce实现协同过滤中每个用户看过的项目集合

一、知识准备 hadoop自带的例子在 D:\HADOOP_HOME\hadoop-2.6.4\share\hadoop\mapreduce\sources\hadoop-mapreduce-examples 2.6.0-source.jar 我记得当年面试的时候就问中位数的问题不过是数据流下的中位数,一问便知是否搞过hadoop。 二、代码实现 2.1 Mapper package cf; import java.io.IOException; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; public class MovieMapper1 extends Mapper<LongWritable, Text, Text, Text> { public void map(LongWritable ikey, Text ivalue, Context context) throws IOException, InterruptedException { String[] values = ivalue.toString().split(","); if (values.length!=2) { return ; } String userID = values[0]; String itemID = values[1]; context.write(new Text(userID), new Text(itemID)); } } 2.2 Reducer package cf; import java.io.IOException; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; public class MovieReduce1 extends Reducer<Text, Text, Text, Text> { public void reduce(Text _key, Iterable<Text> values, Context context) throws IOException, InterruptedException { // process values StringBuffer sb = new StringBuffer(); for (Text val : values) { sb.append(val.toString()); sb.append(","); } //value不能直接用StringBuffer 必须转换为String context.write(_key,new Text(sb.toString())); } } 2.3 Main package cf; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class UserItemSetMapReduce { public static void main(String[] args) throws Exception{ Configuration conf = new Configuration(); Job job = new Job(conf, "CFItemSet"); job.setJarByClass(UserItemSetMapReduce.class); job.setMapperClass(MovieMapper1.class); //job.setCombinerClass(cls); // job.setCombinerClass(MovieReduce1.class); job.setReducerClass(MovieReduce1.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job,new Path("hdfs://192.168.58.180:8020/cf/userItem.txt")); //InputPath(job, new Path(otherArgs[0])); //直接写到cf会提示已存在cf,我写成uIO.ttx,以为内容会写入到txt,然没有,默认他是文件夹 FileOutputFormat.setOutputPath(job,new Path("hdfs://192.168.58.180:8020/cf/userItemOut.txt")); System.exit(job.waitForCompletion(true) ? 0 : 1); } } 三、结果分析 3.1 输入 3.2 输出 查看结果发现输出文件的分隔符默认是tab,‘\t’,同时相对于输入文件来说输出结果是逆着的,类似沾,莫非context就是这样的先进后出、 3.3日志分析 只列出了主要部分的日志 DEBUG - PrivilegedAction as:hxsyl (auth:SIMPLE) from:org.apache.hadoop.mapreduce.Job.getCounters(Job.java:765) INFO - Counters: 38 File System Counters FILE: Number of bytes read=538 FILE: Number of bytes written=509366 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=106 HDFS: Number of bytes written=37 HDFS: Number of read operations=13 HDFS: Number of large read operations=0 HDFS: Number of write operations=4 Map-Reduce Framework Map input records=11 Map output records=11 Map output bytes=44 Map output materialized bytes=72 Input split bytes=107 Combine input records=0 Combine output records=0 Reduce input groups=5 Reduce shuffle bytes=72 Reduce input records=11 Reduce output records=5 Spilled Records=22 Shuffled Maps =1 Failed Shuffles=0 Merged Map outputs=1 GC time elapsed (ms)=3 CPU time spent (ms)=0 Physical memory (bytes) snapshot=0 Virtual memory (bytes) snapshot=0 Total committed heap usage (bytes)=462422016 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=53 File Output Format Counters Bytes Written=37 DEBUG - PrivilegedAction as:hxsyl (auth:SIMPLE) from:org.apache.hadoop.mapreduce.Job.updateStatus(Job.java:323) DEBUG - stopping client from cache: org.apache.hadoop.ipc.Client@37afeb11 DEBUG - removing client from cache: org.apache.hadoop.ipc.Client@37afeb11 DEBUG - stopping actual client because no more references remain: org.apache.hadoop.ipc.Client@37afeb11 DEBUG - Stopping client DEBUG - IPC Client (521081105) connection to /192.168.58.180:8020 from hxsyl: closed DEBUG - IPC Client (521081105) connection to /192.168.58.180:8020 from hxsyl: stopped, remaining connections 0 大神分析一下如何执行的,看着日志....Map如何输入的,执行几次等。

优秀的个人博客,低调大师

php开发文章发布示例(正则表达式实例开发)

存档: post.php 1 <form method="post" action="viewthread.php" target="_blank"> 2 <h2 align="center">发表文章实例开发</h2> 3 <div style="width:200;float:left"> 4 <h5>选项</h5> 5 <ul style="list-style:none;margin:0px;padding:0px"> 6 <li><input type="checkbox" name="parse[]" value="1">删除HTML标签</li> 7 <li><input type="checkbox" name="parse[]" value="2">转换HTML标签为实体</li> 8 <li><input type="checkbox" name="parse[]" value="3">使用UBB代码</li> 9 <li><input type="checkbox" name="parse[]" value="4">开启URL识别</li> 10 <li title="可用的表情: 11 【:),/wx,微笑】【:@,/fn,发怒】 12 【:kiss,/kill,/sa,示爱】 13 【:p,/tx,偷笑】【:q,/dk,大哭】"> 14 <input type="checkbox" name="parse[]" value="5">使用表情</li> 15 <li><input type="checkbox" name="parse[]" value="6">禁用非法关键字</li> 16 <li><input type="checkbox" name="parse[]" value="7">PHP代码设为高亮</li> 17 <li><input type="checkbox" name="parse[]" value="8">原样显示</li> 18 <li><input type="checkbox" name="parse[]" value="9">同步换行</li> 19 </ul> 20 </div> 21 <div style="width:300;float:left"> 22 <h5>标题<input type="text" name="subject" size=50></h5> 23 <h5>内容<textarea rows="7" cols="50" name="message"></textarea></h5> 24 <input type="submit" name="replysubmit" value="发表帖子"> 25 </div> 26 </form> viewthread.php 1 <?php 2 require "article.class.php"; 3 $article = new Article($_POST["subject"],$_POST["message"],$_POST["parse"]); 4 echo $article->getSubject(); 5 echo "<hr>"; 6 echo $article->getMessage(); 7 ?> article.class.php 1 <?php 2 class Article{ 3 private $subject; 4 private $message; 5 function __construct($subject="",$message="",$parse=array()){ 6 $this->subject = $this->html2Text($subject); 7 if(!empty($parse)){ 8 foreach($parse as $value){ 9 switch($value){ 10 case 1: 11 $message = $this->delHtmlTags($message); 12 break; 13 case 2: 14 $message = $this->html2Text($message); 15 break; 16 case 3: 17 $message = $this->UBBCode2Html($message); 18 break; 19 case 4: 20 $message = $this->parseURL($message); 21 break; 22 case 5: 23 $message = $this->parseSmilies($message); 24 break; 25 case 6: 26 $message = $this->disableKeyWords($message); 27 break; 28 case 7: 29 $message = $this->prasePHPCode($message); 30 break; 31 case 8: 32 $message = $this->prasePer($message); 33 break; 34 case 9: 35 $message = $this->nltobr($message); 36 break; 37 } 38 } 39 } 40 $this->message = $message; 41 } 42 43 private function delHtmlTags($message){ 44 return strip_tags($message); 45 } 46 47 private function html2Text($message){ 48 return htmlspecialchars(stripslashes($message)); 49 } 50 51 private function UBBCode2Html($message){ 52 $pattern = array( 53 '/\[b\]/i','/\[\/b\]/i','/\[i\]/i', 54 '/\[\/i\]/i','/\[u\]/i','/\[\/u\]/i', 55 '/\[font=([^\[\<]+?)\]/i', 56 '/\[color=([#\w]+?)\]/i', 57 '/\[size=(\d+?)\]/i', 58 '/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i', 59 '/\[align=(left|center|right)\]/i', 60 '/\[url=www.([^\["\']+?)\](.+?)\[\/url\]/is', 61 '/\[url=(https?|ftp|gopher|news|telnet){1}:\/\/([^\["\']+?)\](.+?)\[\/url]/is', 62 '/\[email\]\s*([a-z0-9\-_.+]+)@([a-z0-9\-_.]+)\s*\[\/email\]/i', 63 '/\[email=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\](.+?)\[\/email\]/is', 64 '/\[img\](.+?)\[\/img\]/', 65 '/\[\/color\]/i', 66 '/\[\/size\]/i', 67 '/\[\/font\]/i', 68 '/\[\/align\]/' 69 ); 70 71 $replace = array( 72 '<b>','</b>','<i>', 73 '</i>','<u>','</u>', 74 '<font face="\\1">', 75 '<font color="\\1">', 76 '<font size="\\1">', 77 '<font style=\"font-size:\\1\">', 78 '<p align="\\1">', 79 '<a href="http://www.\\1" target="_blank">\\2</a>', 80 '<a href="\\1://\\2" target="_blank">\\3</a>', 81 '<a href="mailto:\\1@\\2">\\1@\\2</a>', 82 '<a href="mailto:\\1@\\2">\\3</a>', 83 '<img src="\\1">', 84 '</font>','</font>','</font>','</p>' 85 ); 86 return preg_replace($pattern,$replace,$message); 87 } 88 89 private function cuturl($url){ 90 $length = 65; 91 $url = substr(strtolower($url),0,4) == 'www.'?"http://$url":$url; 92 $urllink = "<a href=\"".$url.'"target="_blank">'; 93 if(strlen($url)>$length){ 94 $url = substr($url,0,intval($length*0.5)).'...'.substr($url,-intval($length*0.3)); 95 } 96 $urllink .=$url.'</a>'; 97 return $urllink; 98 } 99 100 private function parseURL($message){ 101 $urlPattern = "/(www.|https?:\/\/|ftp:\/\/|news:\/\/|telnet:\/\/){1}([^\[\"']+?)(com|net|org)(\/[\w-\.\/?\%\&\=]*)?/ei"; 102 return preg_replace($urlPattern,"\$this->cuturl('\\1\\2\\3\\4')",$message); 103 } 104 105 private function parseSmilies($message){ 106 $pattern = array( 107 '/:\)|\/wx|微笑/i', 108 '/:@|\/fn|发怒/i', 109 '/:kiss|\/kill|\/sa|示爱/', 110 '/:p|\/tx|偷笑/i', 111 '/:q|\/dk|大哭/i' 112 ); 113 $replace = array( 114 '<img src="smilies/smile.png" alt="微笑">', 115 '<img src="smilies/huffy.png" alt="发怒">', 116 '<img src="smilies/kiss.png" alt="示爱">', 117 '<img src="smilies/titter.png" alt="偷笑">', 118 '<img src="smilies/cry.png" alt="大哭">' 119 ); 120 return preg_replace($pattern,$replace,$message); 121 } 122 123 private function disableKeyWords($message){ 124 $keywords_disable = array("非法关键字一","非法关键字二","非法关键字三"); 125 return str_replace($keywords_disable,"**",$message); 126 } 127 128 private function prasePHPCode($message){ 129 $pattern = '/(<\?.*?\?>)/ise'; 130 $replace = '"<pre style=\"background:#ddd\">".highlight_string("\\1",true)."</pre>"'; 131 return preg_replace($pattern,$replace,$message); 132 } 133 134 private function prasePer($message){ 135 return '<pre>'.$message.'</pre>'; 136 } 137 138 private function nltobr($message){ 139 return nl2br($message); 140 } 141 142 public function getSubject(){ 143 return '<h1 align=center>'.$this->subject.'</h1>'; 144 } 145 146 public function getMessage(){ 147 return $this->message; 148 } 149 } 150 ?> 结果如下: 您可以考虑给博主来个小小的打赏以资鼓励,您的肯定将是我最大的动力。thx. 微信打赏 支付宝打赏 作 者: Angel_Kitty 出 处:http://www.cnblogs.com/ECJTUACM-873284962/ 关于作者:潜心机器学习以及信息安全的综合研究。如有问题或建议,请多多赐教! 版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。 特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我 声援博主:如果您觉得文章对您有帮助,可以点击右下角【推荐】推荐一下该博文。您的鼓励是作者坚持原创和持续写作的最大动力!

优秀的个人博客,低调大师

RAG生产环境性能优化:向量索引选型与混合过滤实战方案

上周四晚上九点,客服问答群的告警消息开始刷屏。P99延迟从5ms涨到238ms,召回率从92%掉到78%。用户问“发票怎么开”,系统回一段“会员积分规则”。这系统是RAG,上个月刚上生产,demo阶段跑得飞快。10万向量时查询秒回,演示效果惊艳,领导当场拍板上线。全量导完1000万条客服文档,问题全冒出来。团队第一反应是换Embedding模型,连夜试了三个,召回纹丝不动。折腾两天,EXPLAIN一跑,问题根本不在模型。

优秀的个人博客,低调大师

ASCII 走私技术对邮件钓鱼过滤体系的威胁与防御研究

随着邮件安全防护体系向人工智能驱动的检测架构演进,威胁攻击者开始将面向大语言模型的对抗手段迁移至传统邮件钓鱼场景。ASCII 走私(ASCII smuggling)技术利用 Unicode 标签区块不可见字符,在不改变人类阅读视觉效果的前提下割裂文本关键字,同时干扰传统特征匹配与大语言模型分词解析流程,实现对邮件安全网关的绕过。本文以微软 2026 年监测到的大规模金融诱饵钓鱼攻击事件为研究样本,梳理 ASCII 走私技术的技术实现逻辑,对比其与传统文本加盐混淆手段的差异,剖析该攻击活动的基础设施、传播时序、行为特征,分析其对签名规则、机器学习分类器、大语言模型扫描组件带来的现实挑战。结合攻击样本的技术特征,从文本预处理、多维度特征关联检测、多模态校验、第三方平台滥用治理、组织侧安全运营多个层面提出可落地的防御路径。反网络钓鱼技术专家芦笛指出,AI 对抗技术向传统网络钓鱼场景迁移已经成为确定性趋势,防御体系不能仅依赖单一内容检测能力,必须构建字符预处理 特征规则 上下文 可视化校验的闭环防护链条。研究表明,单纯依靠模型迭代无法抵御此类字符级对抗扰动,文本归一化预处理是阻断 ASCII 走私攻击的基础前提,相关研究结论可为企业邮件安全网关的策略优化、威胁狩猎工作提供参考依据。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册