当前位置: 首页 > news >正文

商业规划设计公司单页网站怎么优化

商业规划设计公司,单页网站怎么优化,网页怎么做网站地图,软件技术毕业设计论文这是 git diff 后的效果,感觉挺简单的,不就是 比较新旧版本,新增了就用 "" 显示新加一行,删除了就用 "-" 显示删除一行,修改了一行就用 "-"、"" 显示将旧版本中的该行干掉了并…

这是 git diff 后的效果,感觉挺简单的,不就是 比较新旧版本,新增了就用 "+" 显示新加一行,删除了就用 "-" 显示删除一行,修改了一行就用 "-"、"+" 显示将旧版本中的该行干掉了并且新版本中增加了一行,即使用 "删除" + "新增" 操作代替 "修改" 操作,然后就用

然后我们写的测试代码如下:

import com.goldwind.ipark.common.util.MyStringUitls;
import org.apache.commons.text.similarity.LevenshteinDistance;import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;public class MyDiffTest {public static void main(String[] args) {List<String> lines_old = loadTxtFile2List("C:\\E\\javaCode\\git\\outer_project\\guodiantou\\gdtipark-user-servie\\src\\main\\java\\com\\goldwind\\ipark\\base\\test\\DemoClass1.java" );List<String> lines_new = loadTxtFile2List("C:\\E\\javaCode\\git\\outer_project\\guodiantou\\gdtipark-user-servie\\src\\main\\java\\com\\goldwind\\ipark\\base\\test\\DemoClass2.java");// lines1的起始行和 lines2 的起始行做映射// 扫描旧版本中的每一行int size = lines_old.size();for( int i=0;i<size;i++ ){// 从新版本中找该行String line_old = lines_old.get(i);String line_new = lines_new.get(i);// 如果发现版本中中该行的数据变了,那么提示删除了旧的行,添加了新的行if( line_new.equals( line_old ) ){System.out.println( line_old );}else {System.out.println( "- " + line_old );System.out.println( "+ " + line_new );}}// xxxx        xxxx1          -xxxx// yyyy        yyyy           +xxxx1// xxxxxx      xxxxxx         xxxxxx// zzzz        zzzz           zzzz}private static List<String> loadTxtFile2List(String filePath) {BufferedReader reader = null;List<String> lines = new ArrayList<>();try {reader = new BufferedReader(new FileReader(filePath));String line = reader.readLine();while (line != null) {// System.out.println(line);lines.add( line );line = reader.readLine();}return lines;} catch (Exception e) {e.printStackTrace();return null;} finally {if (reader != null) {try {reader.close();} catch (Exception e) {e.printStackTrace();}}}}
}

其中用到的2个新旧版本的文本如下:

DemoClass1.java:
import com.goldwind.ipark.common.exception.BusinessLogicException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.text.similarity.LevenshteinDistance;@Slf4j
public class DemoClass1 {private static final LevenshteinDistance LEVENSHTEIN_DISTANCE = LevenshteinDistance.getDefaultInstance();public static String null2emptyWithTrim( String str ){if( str == null ){str = "";}str = str.trim();return str;}public static String requiredStringParamCheck(String param, String paramRemark) {param = null2emptyWithTrim( param );if( param.length() == 0 ){String msg = "操作失败,请求参数 \"" + paramRemark + "\" 为空";log.error( msg );throw new BusinessLogicException( msg );}return param;}public static double calculateSimilarity( String str1,String str2 ){int distance = LEVENSHTEIN_DISTANCE.apply(str1, str2);double similarity = 1 - (double) distance / Math.max(str1.length(), str2.length());System.out.println("相似度:" + similarity);return similarity;}
}

DemoClass2.java:
import com.goldwind.ipark.common.exception.BusinessLogicException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.text.similarity.LevenshteinDistance;@Slf4j
public class DemoClass2 {private static final LevenshteinDistance LEVENSHTEIN_DISTANCE = LevenshteinDistance.getDefaultInstance();private static final LevenshteinDistance LEVENSHTEIN_DISTANCE1 = LevenshteinDistance.getDefaultInstance();private static final LevenshteinDistance LEVENSHTEIN_DISTANCE2 = LevenshteinDistance.getDefaultInstance();public static String null2emptyWithTrim( String str ){if( str == null ){str = "";}str = str.trim();return str;}public static String requiredStringParamCheck(String param, String paramRemark) {param = null2emptyWithTrim( param );if( param.length() == 0 ){String msg = "操作失败,请求参数 \"" + paramRemark + "\" 为空";log.error( msg );throw new BusinessLogicException( msg );}return param;}public static double calculateSimilarity( String str1,String str2 ){int distance = LEVENSHTEIN_DISTANCE.apply(str1, str2);double similarity = 1 - (double) distance / Math.max(str1.length(), str2.length());System.out.println("相似度:" + similarity);return similarity;}
}
DemoClass2.java 相较于 DemoClass1.java 的区别是 "public class" 后面的类名不同,"private static final LevenshteinDistance LEVENSHTEIN_DISTANC..." 多复制了2行并改了名称,然后运行后显示差别如下:
import com.goldwind.ipark.common.exception.BusinessLogicException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.text.similarity.LevenshteinDistance;@Slf4j
- public class DemoClass1 {
+ public class DemoClass2 {private static final LevenshteinDistance LEVENSHTEIN_DISTANCE = LevenshteinDistance.getDefaultInstance();
- 
+     private static final LevenshteinDistance LEVENSHTEIN_DISTANCE1 = LevenshteinDistance.getDefaultInstance();
-     public static String null2emptyWithTrim( String str ){
+     private static final LevenshteinDistance LEVENSHTEIN_DISTANCE2 = LevenshteinDistance.getDefaultInstance();
-         if( str == null ){
+ 
-             str = "";
+     public static String null2emptyWithTrim( String str ){
-         }
+         if( str == null ){
-         str = str.trim();
+             str = "";
-         return str;
+         }
-     }
+         str = str.trim();
- 
+         return str;
-     public static String requiredStringParamCheck(String param, String paramRemark) {
+     }
-         param = null2emptyWithTrim( param );
+ 
-         if( param.length() == 0 ){
+     public static String requiredStringParamCheck(String param, String paramRemark) {
-             String msg = "操作失败,请求参数 \"" + paramRemark + "\" 为空";
+         param = null2emptyWithTrim( param );
-             log.error( msg );
+         if( param.length() == 0 ){
-             throw new BusinessLogicException( msg );
+             String msg = "操作失败,请求参数 \"" + paramRemark + "\" 为空";
-         }
+             log.error( msg );
-         return param;
+             throw new BusinessLogicException( msg );
-     }
+         }
- 
+         return param;
-     public static double calculateSimilarity( String str1,String str2 ){
+     }
-         int distance = LEVENSHTEIN_DISTANCE.apply(str1, str2);
+ 
-         double similarity = 1 - (double) distance / Math.max(str1.length(), str2.length());
+     public static double calculateSimilarity( String str1,String str2 ){
-         System.out.println("相似度:" + similarity);
+         int distance = LEVENSHTEIN_DISTANCE.apply(str1, str2);
-         return similarity;
+         double similarity = 1 - (double) distance / Math.max(str1.length(), str2.length());
-     }
+         System.out.println("相似度:" + similarity);
- }
+         return similarity;

为啥???

如上两张图片,旧版本的第10行和新版本的第10行对应,从直观上看新版本的第11、12行是在旧版本的第10行和第11行之间插进去的,但是程序并不这么认为,它会认为将旧版本的第11行的空白行修改为了新版本的 “private static final LevenshteinDistance LEVENSHTEIN_DISTANCE1 = LevenshteinDistance.getDefaultInstance();” 为什么我们人眼会这么直观的感觉到 新版本的 第11、12行时插进去的,因为我们比较了新旧版本的第7、8、9、10行都差不多,旧版本的11~27行和新版本的 13~29行都差不多,所以自然而然的认为新版本的11、12行是直接插进去的,那么现在我们就来算法实现吧!( ps:前文中的 “差不多” 是差几多?是完全equals 还是很像?”其实这里可以设置一个阈值,使用求字符串的相似度算法求出相似度,网上有现成的类库求相似度,自己也可以使用动态规划写一个简单的字符串相似度算法 )

感觉恰当的算法的执行过程应该是这样的:

新旧版本各维持一个行号游标:index_old、index_new,最开始这两个游标相同,越往后可能不同,但是他们表示的行的内容应该是应该相似的,因为新版本的修改会导致内容越来越 “错位”。假设我们从上面2张图片的第7行开始描:

        1. 最开始 index_old = index_new = 7,算法检测到新旧版本的第7行的内容相同( 后面我们就尽量用伪代码表示,就不说这么多啰里啰嗦的话了 ),即 lines_old[ 7] = lines_new[ 7]。

        2. index_old++,index_new++,都变为8,算法检测到 lines_old[ 8 ] != lines_new[ index_new ],并且他们的相似度很高,所以算法判断新版本的第8行相较于旧版本的第8行是做了修改操作。

        3. index_old++,index_new++,都变为9,算法检测到 lines_old[ 9 ] = lines_new[ 9 ]。

        4. index_old++,index_new++,都变为10,算法检测到 lines_old[ 10 ] = lines_new[ 10 ]。

        5.  index_old++,index_new++,都变为11,算法检测到 lines_old[ 11 ] !=  lines_new[ 11 ],并且这两行的文本内容及不相似,所以判断新版本是在旧版本的第11行插入了一行 “private static final LevenshteinDistance LEVENSHTEIN_DISTANCE1 =LevenshteinDistance.getDefaultInstance();”,所以此时旧版本的第11行就和新版本的第11行对应不上了,而是和新版本的第12行做对应。

        6.  index_old 不变,index_new++,index_old 还是11,index_new 变为 12,即旧版本的第11行要和新版本的第12行做对应,就像找老婆一样,旧7和新7结为了夫妻,旧8和新8结为了夫妻( 虽然有一点点的裂痕,但不打紧 ),新9和新9结为了夫妻,...,所以旧11也要在新版本中找到一个新x作为自己的伴侣,本来已经找到了一个新11,但是发现新11和自己三观差别很大,根本合不来,所以pass掉,继续找,现在发现了下一个相亲对象 新12,发现lines_old[ 11 ] 和 lines_new[ 12 ] 相似度还是差别很大,所以算法判断新版本又插入了一个新行 “private static final LevenshteinDistance LEVENSHTEIN_DISTANCE2 = LevenshteinDistance.getDefaultInstance();”。

        7. index_old 不变,index_new++,index_old 还是11,index_new 变为 13,因为 lines_old[ 11 ] = lines_new[ 13 ],所以 旧11 很幸运的找到了自己的伴侣 新13,。

        8.  index_old++,index_new++,index_old变为12,index_new变为14,因为 lines_old[ 12 ] = lines_new[ 14 ],所以此步未检测到变化。

        ...

改进后的测试代码如下:

todo

http://www.ds6.com.cn/news/48522.html

相关文章:

  • 腾讯云主机做网站最好的seo外包
  • 网站建设费用表知乎关键词排名优化工具
  • b2c网站策划书高州网站seo
  • 资讯网站做app一键搭建网站
  • 哪个网站做推销产品全球疫情最新数据统计
  • 免费广州网站开发维护万能的搜索引擎
  • 宁波正规网站建设使用方法百度爱采购
  • 怎么做一家网站河北百度推广电话
  • 微信公众号平台官网客服电话优化大师使用心得
  • 黄岩网站开发百度关键词热度排名
  • 做网站网页尺寸是多少钱武汉网站建设公司
  • 高端的佛山网站建设3天网站seo优化成为超级品牌
  • 网站建设而深圳seo外包
  • 淄博网站关系网站优化公司
  • 黑龙江网站建设seo优化百度竞价可以自学吗
  • 联盟网营销网站seo推广
  • 如何做中国古城的网站怎么做电商生意
  • 山西省住房和城乡建设厅网站报名百度问一问免费咨询
  • 郑州做网站公司排建站平台如何隐藏技术支持
  • 一个公司网站备案正规的关键词优化软件
  • 网上商城用wordpresswindows优化大师手机版
  • 南京网站建设流程黄山seo排名优化技术
  • 电商网站里的水果图片怎么做的域名注册查询系统
  • 沈阳网站制作招聘网泉州全网营销推广
  • 广州天河网站制作海淀区seo全面优化
  • 高端网站制作费用百度快照优化培训班
  • 电子商务网站建设的盈利模式磁力搜索引擎不死鸟
  • 免费ftp网站陕西网页设计
  • 网站建设图标google关键词分析工具
  • 网站建站要交税吗不付费免费网站