基于pgfSweave的漂亮中文动态文档
- 格式:pdf
- 大小:464.59 KB
- 文档页数:4
tex文件的中文算法流程伪代码在撰写科技论文或者技术文档中,算法流程图和伪代码是非常重要的部分。
而在使用LaTeX撰写中文文档时,如何添加中文算法流程图和伪代码是一个值得探讨的问题。
一般来说,我们可以使用algorithm2e宏包来实现中文算法流程伪代码的编写。
具体步骤如下:1.在导言区调用algorithm2e宏包,并设置中文选项。
usepackage[UTF8, heading, scheme=plain]{ctex}usepackage{algorithm2e}2.在正文中,使用algorithm环境来编写算法,并设置中文标题、关键字等信息。
begin{algorithm}[h]tcaption{中文算法流程}tKwIn{输入参数1,输入参数2}tKwOut{输出结果}tBlankLinetWhile{循环条件}{tt执行操作1;tt执行操作2;t}tReturn{返回结果}end{algorithm}其中,KwIn、KwOut和Return分别表示输入、输出和返回操作,While表示循环操作。
3.在伪代码中添加中文注释,即可实现中文算法流程伪代码的编写。
begin{algorithm}[h]tcaption{中文算法伪代码}tKwIn{输入参数1,输入参数2}tKwOut{输出结果}tBlankLinetWhile{循环条件}{tt// 执行操作1tt操作1;tt// 执行操作2tt操作2;t}tReturn{返回结果}end{algorithm}通过以上步骤,我们可以实现中文算法流程伪代码的编写。
需要注意的是,在编写算法时,要注意代码的格式、缩进和注释的位置,以便于阅读和理解。
Hugo博客中⽂指南(基础教程)1. 安装 Hugo从 Hugo 项⽬主页下载 Releases ⽂件,解压hugo.exe⽂件到C:\Windows\System32⽬录下。
2. 创建站点hugo new site mysite新的站点⽂件夹 mysite 就⾃动⽣成到了当前⽬录下:在执⾏完hugo new site命令后你会得到⼀个包含以下⽂件的⽬录。
.├── archetypes/├── config.toml├── content/ # 储存⽹站的所有⽂章内容├── data/├── layouts/ # 全局样式,优先级⾼于主题下的 layouts ⽂件夹├── static/ # 静态⽂件,优先级⾼于主题下的 static ⽂件夹└── themes/ # 主题⽬录3. 新建页⾯和⽂章新建⼀个 about 页⾯:hugo new about.mdabout.md ⾃动⽣成到了 content/about.md,内容如下:---title: "About"date: 2020-04-07T22:05:28+08:00draft: true---创建第⼀篇⽂章,放到 post ⽬录:hugo new post/myfirst.mdmyfirst.md ⾃动⽣成到了 content/post/myfirst.md,内容如下:---title: "Myfirst"date: 2020-04-07T22:05:28+08:00draft: true---其中 draft: true 表⽰为草稿⽂件,正式发布前需将值修改为 false,或者直接删除 draft 整个参数,否则正式发布时不会⽣成⽂章。
4. 安装主题到或从 Github 下载⼀款主题,解压到 theme ⽬录下:通过命令⾏的⽅式使⽤主题:hugo -t 主题⽬录名通过在 config.toml 配置使⽤:theme = "主题⽬录名"5. 编译输出(构建 Hugo ⽹站)在 Hugo ⽹站⽂件夹的根⽬录下,执⾏hugo命令来构建。
Package‘wordcloud2’October12,2022Type PackageTitle Create Word Cloud by'htmlwidget'Version0.2.1Author Dawei Lang[aut,cre],Guan-tin Chien[aut,author for'wordcloud2.js']Description A fast visualization tool for creating wordcloudby using'wordcloud2.js'.'wordcloud2.js'is a JavaScript library to createwordle presentation on2D canvas or HTML<https:///wordcloud2.js/>. License GPL-2Depends R(>=3.1.0)LazyData TRUEVignetteBuilder knitrImports htmlwidgets,base64enc,grDevices,graphicsSuggests knitr,rmarkdown,webshotEnhances shiny(>=0.12)URL https:///lchiffon/wordcloud2BugReports https:///lchiffon/wordcloud2/issuesMaintainer Dawei Lang<**********************>RoxygenNote5.0.1NeedsCompilation noRepository CRANDate/Publication2018-01-0315:20:37UTCR topics documented:+.wordcloud2 (2)demoFreq (2)demoFreqC (3)letterCloud (3)WCtheme (4)wordcloud2 (4)wordcloud2-shiny (6)1Index7 +.wordcloud2Change the themes of wordcloud2DescriptionFunction for Creating wordcloud themeUsage##S3method for class wordcloud2e1+e2Argumentse1wordcloud2objecte2wordcloud2themesExampleswc=wordcloud2(demoFreq)wc+WCtheme(1)wc+WCtheme(2)wc+WCtheme(3)wc+WCtheme(2)+WCtheme(3)demoFreq Demo dataset with Words and FrequencyDescriptionA datafile of words and frequency from tm packageUsagedemoFreqFormatA data set with1011observations of2variables,words and frequancydemoFreqC Demo dataset with Chinese character Words and FrequencyDescriptionA datafile of words and frequency from tm packageUsagedemoFreqCFormatA data set with885observations of2variables,words and frequancy letterCloud Create wordcloud with the shape of a wordDescriptionFunction for Creating wordcloud with the shape of a wordUsageletterCloud(data,word,wordSize=0,letterFont=NULL,...)Argumentsdata A data frame including word and freq in each columnword A word to create shape for wordcloud.wordSize Parameter of the size of the word.letterFont Letter font...Other parameters for wordcloud.Exampleslibrary(wordcloud2)letterCloud(demoFreq,"R")WCtheme Change the themes of wordcloud2DescriptionFunction for Creating wordcloud themeUsageWCtheme(class=1)Argumentsclass class for theme in wordcloud2Exampleswc=wordcloud2(demoFreq)wc+WCtheme(1)wc+WCtheme(2)wc+WCtheme(3)wc+WCtheme(2)+WCtheme(3)wordcloud2Create wordcloud by wordcloud2.jsDescriptionFunction for Creating wordcloud by wordcloud2.jsUsagewordcloud2(data,size=1,minSize=0,gridSize=0, fontFamily= Segoe UI ,fontWeight= bold ,color= random-dark ,backgroundColor="white",minRotation=-pi/4,maxRotation=pi/4,shuffle=TRUE,rotateRatio=0.4,shape= circle ,ellipticity=0.65,widgetsize=NULL,figPath=NULL,hoverFunction=NULL)Argumentsdata A data frame including word and freq in each columnsize Font size,default is1.The larger size means the bigger word.minSize A character string of the subtitlegridSize Size of the grid in pixels for marking the availability of the canvas the larger the grid size,the bigger the gap between words.fontFamily Font to use.fontWeight Font weight to use,e.g.normal,bold or600color color of the text,keyword’random-dark’and’random-light’can be used.color vector is also supported in this parambackgroundColorColor of the background.minRotation If the word should rotate,the minimum rotation(in rad)the text should rotate.maxRotation If the word should rotate,the maximum rotation(in rad)the text should rotate.Set the two value equal to keep all text in one angle.shuffle Shuffle the points to draw so the result will be different each time for the same list and settings.rotateRatio Probability for the word to rotate.Set the number to1to always rotate.shape The shape of the"cloud"to draw.Can be a keyword present.Available presents are’circle’(default),’cardioid’(apple or heart shape curve,the most knownpolar equation),’diamond’(alias of square),’triangle-forward’,’triangle’,’pen-tagon’,and’star’.ellipticity degree of"flatness"of the shape wordcloud2.js should draw.widgetsize size of the widgetsfigPath The path to afigure used as a mask.hoverFunction Callback to call when the cursor enters or leaves a region occupied by a word.A string of java script function.Exampleslibrary(wordcloud2)#Global variables can go herewordcloud2(demoFreq)wordcloud2(demoFreq,size=2)wordcloud2(demoFreq,size=1,shape= pentagon )wordcloud2(demoFreq,size=1,shape= star )wordcloud2(demoFreq,size=2,color="random-light",backgroundColor="grey")6wordcloud2-shiny wordcloud2(demoFreq,size=2,minRotation=-pi/2,maxRotation=-pi/2)wordcloud2(demoFreq,size=2,minRotation=-pi/6,maxRotation=-pi/6,rotateRatio=1)wordcloud2(demoFreq,size=2,minRotation=-pi/6,maxRotation=pi/6,rotateRatio=0.9)wordcloud2(demoFreqC,size=2,color="random-light",backgroundColor="grey")wordcloud2(demoFreqC,size=2,minRotation=-pi/6,maxRotation=-pi/6,rotateRatio=1)#Color VectorcolorVec=rep(c( red , skyblue ),length.out=nrow(demoFreq))wordcloud2(demoFreq,color=colorVec,fontWeight="bold")wordcloud2(demoFreq,color=ifelse(demoFreq[,2]>20, red , skyblue ))wordcloud2-shiny Plot wordcloud2in shinyDescriptionFunction for plotting wordcloud2in shinyUsagewordcloud2Output(outputId,width="100%",height="400px")renderWordcloud2(expr,env=parent.frame(),quoted=FALSE)wordcloud2Output(outputId,width="100%",height="400px")renderWordcloud2(expr,env=parent.frame(),quoted=FALSE)ArgumentsoutputId output variable to read fromwidth,height Must be a valid CSS unit(like"100%","400px","auto")or a number,which will be coerced to a string and have"px"appended.expr An expression that generates a networkD3graphenv The environment in which to evaluate expr.quoted Is expr a quoted expression(with quote())?This is useful if you want to save an expression in a variable.DetailsUse renderWordcloud2to render an wordcloud2object and use wordcloud2Output output an word-cloud2object.See more details in shiny package.Index∗datasetsdemoFreq,2demoFreqC,3+.wordcloud2,2demoFreq,2demoFreqC,3letterCloud,3renderWordcloud2(wordcloud2-shiny),6 WCtheme,4wordcloud2,4wordcloud2-shiny,6wordcloud2Output(wordcloud2-shiny),67。
/fx125437@126/blog/static/11357041201110279126622/?latestBlogFlunet中的动网格设置不仅包含网格的更新方法,主要包括smoothing;layering;remeshing 三种方法,同时也需要设置相关的边界和流体区域的运动类型(Stationary Zones;Rigid Body Motion;Deforming Motion ;User-Defined Motion )以及对于刚体运动所需要的运动方式的定义。
对于相关运动方式的定义fluent提供了两种方式来定义其运动轨迹(UDF&Profile),下面分别介绍:ProfileUDFFluent定义的三个宏来编写相关的动网格UDF先介绍DEFINE_CG_MOTION宏1、描述通过使用DEFINE_CG_MOTION宏来指定特定动态区域的运动。
该宏能够指定每一时间步的线速度与角速度。
ANSYS FLUENT利用这些速度更新动态区域的节点位置。
该宏只能用于编译型。
2、语法说明DEFINE_CG_MOTION(name,dt,vel,omega,time,dtime)(1)name:宏名,由用户指定,需要符合UDF中宏命名规范。
(2)dt:类型为Dynamic_Thread *dt,是一个包含了用户指定的动网格属性结构的指针。
(3)vel:数据类型为real vel[],速度向量,vel[0]表示x方向线速度,vel[1]表示y方向,vel[2]为Z方向。
(4)omega:real omega[],角速度向量。
索引为0~2,分别表示x,y,z方向角速度。
(5)time:类型为real,表示当前时间。
(6)dtime:类型为real,表示时间步该宏的返回类型为void此宏包含有六个参数,其中name是用户提供,其他的参数如dt,vel,omega,time,dtime均有ansys fluent求解器传递。
1、关于万维网,以下说法正确的是万维网是一种建立在Internet上的信息检索系统;万维网主要以“超文本”或“超媒体”形式提供信息;万维网即因特网;2、WWW是World Wide Web的简称,在浏览网页时遵循的是HTTP协议。
3、以下HTML标记,<br>是非封闭型的。
4、若要求对文档中部分内容在浏览时几乎不做修改地输出,可以用<pre>标记通知浏览器。
5、创建最小的标题的文本标签是<h6></h6>6、对于一个文字超链接,可以设置link、alink、vlink状态的颜色标记。
7、Internet Explorer中默认状态下,层的标记为<Div>8、下列meta、base、link标记如果存在必须放于HTML文档的头部。
9、HTML代码<table width=# or %>表示设置表格的宽度:用像素值或百分比形式。
10、以下标记不能通过选择“查看”à“可视化助理”à“不可见元素”使其可见的是框架边框。
11、使用“插入”→“图像”命令,要将图像从目前网站之外的文件夹插入页面中。
则要在“网站定义”对话框中,设置默认图像文件夹选项,那就会自动复制该图像到网站中的pic 文件夹,而不会产生警告信息。
12、Macromedia Dreamweaver MX 2004中,“站点”这个概念既可表示位于Internet服务器上的远程站点,也可以表示位于本地计算机上的本地站点。
这句话是正确13、如果需要使打开的文件自动被取出,则在“定义远程信息”时要选中打开文件之前取出。
14、Dreamweaver MX 2004中一个网页可以在文档窗口中以3种视图方式打开。
15、在Dreamweaver 中,关于“资源”面板的说法错误的是模板和库不在“资源”面板中显示。
16、站点地图所描述的站点结构,是以主页为开始点。
17、Dreamweaver MX 2004中,设置“页面属性”中“下划线样式”属性,不能去除超链接文字中下划线的是“始终有下划线”和“仅是图像变换时隐藏下划线”两项。
Package‘era’November17,2022Type PackageTitle Year-Based Time ScalesVersion0.4.1Description Provides a consistent representation of year-based time scales as a numeric vector with an associated'era'.There are built-in era definitionsfor many year numbering systems used in contemporary and historic calendars(mon Era,Islamic'Hijri'years);year-based time scales used inarchaeology,astronomy,geology,and other palaeosciences(e.g.Before Present,SI-prefixed'annus');and support for arbitrary user-definederas.Years can converted from any one era to another using a generalisedtransformation function.Methods are also provided for robust casting andcoercion between years and other numeric types,type-stable arithmetic withyears,and pretty-printing in tables.Language en-GBLicense MIT+file LICENSEURL https://era.joeroe.io,https:///joeroe/era BugReports https:///joeroe/era/issuesEncoding UTF-8RoxygenNote7.2.2Depends R(>=2.10)Imports vctrs(>=0.3.0),methods,rlang,pillarSuggests tibble,testthat,covr,knitr,rmarkdown,dplyr,spelling,purrr,tidyr,lubridateVignetteBuilder knitrConfig/testthat/edition3NeedsCompilation noAuthor Joe Roe[aut,cre](<https:///0000-0002-1011-1244>) Maintainer Joe Roe<*************>Repository CRANDate/Publication2022-11-1713:10:04UTC12era R topics documented:era (2)eras (3)era_parameters (4)era_year (5)era_year_parameters (6)is_era (6)is_era_year (7)is_yr (8)this_year (9)yr (10)yr_era (10)yr_transform (11)Index13 era Create an era objectDescriptionAn era object defines the time scale associated with a vector of years(see yr()).era()returns an era object,either by looking up label in the standard eras defined in eras()or,if more than one argument is given,constructing a new definition with the specified parameters.Usageera(label=character(),epoch=NULL,name=label,unit=era_year("Gregorian"),scale=1,direction=-1)Argumentslabel Character.If only one argument is given to era(),the abbreviated label of a standard era defined in eras().Otherwise,the label to give to the era con-structed using the following arguments.epoch Numeric.Epoch year from which years are counted in Gregorian astronomical years(i.e.there is a"year zero").name Character.Full name of the era.Defaults to the value of label.unit An era_year()object describing the name of the year unit and its average length in solar days.Defaults to a Gregorian year(365.2425days).eras3scale Integer.Number of years represented by one unit,e.g.1000for ka.Default:1.direction Are years counted backwards(-1)(the default)or forwards(1)from epoch?ValueAn object of class era.See AlsoOther era definition functions:eras()Other era helper functions:era_parameters,era_year_parameters,era_year,is_era_year(), is_era(),is_yr(),this_year()Examplesera("cal BP")era("T.A.",epoch=-9021,name="Third Age",direction=1)eras Standard era definitionsDescriptionDefinitions of common eras and time scales.eras()lists all available era definitions.eras(label)looks up a specific era by its unique,abbre-viated name(e.g."cal BP").Usageeras(label=NA)Argumentslabel(Optional)Abbreviated names(s)of eras to look up.DetailsLooking up eras by label uses partial matching.ValueA table of era definitions.This can be passed to era()to construct an era object.See AlsoOther era definition functions:era4era_parametersExamples#List all available eraseras()#Look up a specific era by labeleras("cal BP")#With partial matchingeras("cal")era_parameters Get parameters of an eraDescriptionExtracts a specific parameter from an era object.Usageera_label(x)era_epoch(x)era_name(x)era_unit(x)era_scale(x)era_direction(x)Argumentsx An era object.DetailsThe available parameters are:•label–unique,abbreviated label of the era,e.g."cal BP"•epoch–year of origin of the era,e.g.1950for Before Present•name–full name of the era,e.g."calendar years Before Present"•unit–unit of years used,an era_year()object•scale–multiple of years used,e.g.1000for ka/kiloannum•direction–whether years are counted"backwards"or"forwards"from the epoch#’era_year5 ValueValue of the parameter.See AlsoOther era helper functions:era_year_parameters,era_year,era,is_era_year(),is_era(), is_yr(),this_year()Examplesx<-era("cal BP")era_name(x)era_year Year unitsDescriptionera_year objects describe the unit used for a year as its length in days.This value is used in an era definition(era())to enable conversions between eras that use different units(with yr_transform()). Usageera_year(label=character(),days=365.2425)Argumentslabel of the year unit.days Numeric.Average length of the year in solar days.Defaults to a Gregorian year(365.2425days).ValueS3vector of class era_year.See AlsoOther era helper functions:era_parameters,era_year_parameters,era,is_era_year(),is_era(), is_yr(),this_year()Examplesera_year("Julian",365.25)6is_era era_year_parameters Get the parameters of an era_year object.DescriptionExtracts a specific parameter from a year unit object constructed by era_year().Usageera_year_label(x)era_year_days(x)Argumentsx An object of class era_year.ValueValue of the parameter.See AlsoOther era helper functions:era_parameters,era_year,era,is_era_year(),is_era(),is_yr(), this_year()Examplesjulian<-era_year("Julian",365.25)era_year_label(julian)era_year_days(julian)is_era Validation functions for era objectsDescriptionTests whether an object is an era definition(an era object).is_era()tests whether the object in-herits from the S3class era_yr.is_valid_era()performs additional checks to determine whether the object is well-formed(see details).validate_era()throws an informative error message for invalid yr s.is_era_year7Usageis_era(x)validate_era(x)is_valid_era(x)Argumentsx Object to test.DetailsValid era objects:•Must have all parameters set and not NA•Must have a character label parameter•Must have a numeric epoch parameter•Must have a character name parameter•Must have a character unit parameter that is one of the defined units•Must have a positive,integer scale parameter•Must have a direction parameter that is-1(backwards)or1(forwards)Valueis_era()and is_valid_era()return TRUE or FALSE.validate_era()returns x invisibly,and is used for its side-effect of throwing an informative error for invalid objects.See AlsoOther era helper functions:era_parameters,era_year_parameters,era_year,era,is_era_year(), is_yr(),this_year()is_era_year Validation functions for era_year objectsDescriptionTests whether an object is of class era_year(constructed by era_year()).Usageis_era_year(x)Argumentsx Object to test.8is_yrValueTRUE or FALSE.See AlsoOther era helper functions:era_parameters,era_year_parameters,era_year,era,is_era(), is_yr(),this_year()Examplesis_era_year(era_year("Julian",365.25))is_yr Validation functions for yr objectsDescriptionTests whether an object is a vector of years with an era(a yr object).is_yr()tests whether the object inherits from the S3class era_yr.is_valid_yr()performs additional checks to deter-mine whether the object is well-formed(see details).validate_yr()throws an informative error message for invalid yr s.Usageis_yr(x)validate_yr(x)is_valid_yr(x)Argumentsx Object to test.DetailsValid yr objects:•Must contain numeric data(NAs are allowed)•Must have the era attribute set and not NA•Must not have more than one era•Must have an era attribute that is a valid era object(see validate_era())Valueis_yr()and is_valid_yr()return TRUE or FALSE.validate_yr()returns x invisibly,and is used for its side-effect of throwing an informative error for invalid objects.this_year9 See AlsoOther era helper functions:era_parameters,era_year_parameters,era_year,era,is_era_year(), is_era(),this_year()Examplesx<-yr(5000:5050,era("cal BP"))is_yr(x)is_valid_yr(x)validate_yr(x)this_year Current yearDescriptionReturns the current year as a year vector,in the era system specified by era.Usagethis_year(era="CE")Argumentsera An era object or label understood by era().Defaults to the Common Era(era("CE")).ValueA yr vector with the current year.See AlsoOther era helper functions:era_parameters,era_year_parameters,era_year,era,is_era_year(), is_era(),is_yr()Examples#This year in the Common Erathis_year()#This year in the Holocene Epochthis_year("HE")10yr_era yr Create a vector of years with eraDescriptionA yr object represents years with an associated calendar era or time scale.Usageyr(x=numeric(),era=character())Argumentsx A numeric vector of years.era The calendar era used by x.Either:•A string matching one of the standard era labels defined in eras()•An era object constructed with era()ValueA yr(era_yr)object.See AlsoOther years with era functions:yr_era(),yr_transform()Examples#The R Ageyr(1993:2020,"CE")#A bad movieyr(10000,"BC")yr_era Get or set the era of a vector of yearsDescriptionFunctions for extracting or assigning the era of a vector of years.This function does not alter the underlying values of e yr_transform()to convert the values of a yr vector to a new era.Usageyr_era(x)yr_set_era(x,era)yr_era(x)<-valueArgumentsx A vector of years.value,era An era object(see era())to be assigned to x.Valueyr_era(x)returns the existing era associated with x.yr_set_era(x,era)and yr_era(x)<-era return x with the new era assigned.If x is not alreadya yr vector,it will attempt to coerce it into one.See AlsoOther years with era functions:yr_transform(),yr()Examplesx<-5000:5050yr_era(x)<-era("cal BP")yr_era(x)yr_transform Convert years from one era to anotherDescriptionTransform a vector of years from one era to another.Usageyr_transform(x,era=yr_era(x),precision=NA)Argumentsx yr object.A vector of years with an era,see yr().era era object describing the target era,see era().precision Desired precision of the transformation,i.e.the transformed values are rounded to the nearest precision.If NA(the default),no rounding is performed and theexact transformed value is returned.DetailsTransformation between eras uses the scale,epoch,direction and unit parameters of the era definition.NA values for any of these parameters in the source or destination era will cause an error.This is most often encountered when either are measured in’radiocarbon years’,which cannot be related to a calendar time scale without calibration or un-calibration.The transformation function is exact and treats years as a real number scale.This means that transformations between eras with different year units(e.g.Gregorian to Julian)and/or epochs not aligned to1January in the Gregorian calendar(mon Era to Islamic calendars)will likely return non-integer values.The precision argument provides a convenient way to round the result if you do not need this level of precision.It is also useful for working around the ambiguous definition of’present’in various geological time-scales.ValueA yr object in the era specified by era.See AlsoOther years with era functions:yr_era(),yr()Examplesx<-yr(10010:10001,"cal BP")yr_transform(x,era("BCE"))yr_transform(x,era("ka"),precision=1)Index∗era definition functionsera,2eras,3∗era helper functionsera,2era_parameters,4era_year,5era_year_parameters,6is_era,6is_era_year,7is_yr,8this_year,9∗years with era functionsyr,10yr_era,10yr_transform,11era,2,3,5–9era(),3,5,9–11era_direction(era_parameters),4era_epoch(era_parameters),4era_label(era_parameters),4era_name(era_parameters),4era_parameters,3,4,5–9era_scale(era_parameters),4era_unit(era_parameters),4era_year,3,5,5,6–9era_year(),2,4,6,7era_year_days(era_year_parameters),6 era_year_label(era_year_parameters),6 era_year_parameters,3,5,6,7–9eras,3,3eras(),2,10is_era,3,5,6,6,8,9is_era_year,3,5–7,7,9is_valid_era(is_era),6is_valid_yr(is_yr),8is_yr,3,5–8,8,9this_year,3,5–9,9validate_era(is_era),6validate_yr(is_yr),8yr,10,11,12yr(),2,11yr_era,10,10,12yr_era<-(yr_era),10yr_set_era(yr_era),10yr_transform,10,11,11yr_transform(),5,10 13。
Compass技术文档目录一、原理描述:.................................................................................................................................二、术语解释:.................................................................................................................................三、下载地址:.................................................................................................................................四、使用流程: …………………………………………………………………………………….五、基于SSH的compass的实例: …………………………………………………………………一、原理描述:Compass是一流的开放源码JAVA搜索引擎框架,对于你的应用修饰,搜索引擎语义更具有能力。
依靠顶级的Lucene搜索引擎,Compass 结合了,像Hibernate和Spring的流行的框架,为你的应用提供了从数据模型和数据源同步改变的搜索力.并且添加了2方面的特征,事物管理和快速更新优化.Compass的目标是:把java应用简单集成到搜索引擎中.编码更少,查找数据更便捷.二、术语解释:三、下载地址:四、使用流程:五、基于SSH的compass的实例:step1在ssh2的基础上开发加入jar包(compass-2.1.2.jar compass-index-patch.jarlucene-analyzers-2.4.0.jar lucene-core-2.4.0.jar lucene-highlighter-2.4.0.jar paoding-analysis.jar)step2先来看下实体bean的编写Java代码1.package com.v512.example.model;2.import pass.annotations.*;3./**4. * Product entity.5. *6. * @author MyEclipse Persistence Tools7. */8.@Searchable9.public class Product implements java.io.Serializable {10.11. // Fields13. @SearchableId14. private String id;15. @SearchableProperty(name="name",index=Index.ANALYZED,store=Store.YES)16. private String name;17. @SearchableProperty(name="price",index=Index.NOT_ANALYZED,store=Store.YES)18. private Double price;19. @SearchableProperty(name="brand",index=Index.ANALYZED,store=Store.YES)20. private String brand;21. @SearchableProperty(name="description",index=Index.ANALYZED,store=Store.YES)22. private String description;23.24. // Constructors25.26. /** default constructor */27. public Product() {28. }29.30. /** full constructor */31. public Product(String name, Double price, String brand, String description) {32. = name;33. this.price = price;34. this.brand = brand;35. this.description = description;36. }37.38. // Property accessors39.40. public String getId() {41. return this.id;42. }43.44. public void setId(String id) {45. this.id = id;46. }47.48. public String getName() {49. return ;50. }52. public void setName(String name) {53. = name;54. }55.56. public Double getPrice() {57. return this.price;58. }59.60. public void setPrice(Double price) {61. this.price = price;62. }63.64. public String getBrand() {65. return this.brand;66. }67.68. public void setBrand(String brand) {69. this.brand = brand;70. }71.72. public String getDescription() {73. return this.description;74. }75.76. public void setDescription(String description) {77. this.description = description;78. }79.80.}step3属性文件Product.hbm.xmlJava代码1.<?xml version="1.0" encoding="utf-8"?>2.<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"3."/hibernate-mapping-3.0.dtd">4.<!--5. Mapping file autogenerated by MyEclipse Persistence Tools6.-->7.<hibernate-mapping>8. <class name="com.v512.example.model.Product" table="PRODUCT" >9. <id name="id" type="ng.String">10. <column name="ID" length="40" />11. <generator class="uuid.hex" />12. </id>13. <property name="name" type="ng.String">14. <column name="NAME" length="80" />15. </property>16. <property name="price" type="ng.Double">17. <column name="PRICE" precision="6" />18. </property>19. <property name="brand" type="ng.String">20. <column name="BRAND" length="40" />21. </property>22. <property name="description" type="ng.String">23. <column name="DESCRIPTION" length="2000" />24. </property>25. </class>26.</hibernate-mapping>要使用Compass必须加入一个applicationContext-compass.xml文件,文件名可以自行定义这个就不用说了废话step4applicationContext-compass.xml:Java代码1.<?xml version="1.0" encoding="UTF-8"?>2.3.<beans xmlns="/schema/beans"4. xmlns:xsi="/2001/XMLSchema-instance"5. xsi:schemaLocation=" /schema/beans /schema/beans/spring-beans -2.5.xsd"6. default-lazy-init="true">7.8. <!-- 配置compass的注解功能 -->9. <bean id="annotationConfiguration"10. class="passAnnotationsConfiguration">11. </bean>12.13.14. <bean id="compass" class="pass.spring.LocalCompassBean">15. <!-- 配置需要索引的实体映射文件的路径 -->16. <property name="resourceDirectoryLocations">17. <list>18. <value>classpath:com/v512/example/model</value>19. </list>20. </property>21. <!-- 设置存放索引的路径 -->22. <property name="connection">23. <value>/lucene/indexes</value>24. </property>25.26. <!--配置要搜索的类,作用:会根据以下的类建立索引 -->27. <property name="classMappings">28. <list>29. <value>com.v512.example.model.Product</value>30. </list>31. </property>32. <property name="compassConfiguration"33. ref="annotationConfiguration" />34.35. <!--compass的一些属性设置 -->36. <property name="compassSettings">37. <props>38. <prop key="compass.transaction.factory">39. pass.spring.transaction.SpringSyncTransactionFactory40. </prop>41. <prop key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer">net.paoding.analysis.analyzer.PaodingAnalyzer </prop>42. </props>43. </property>44. <!--compass的事务管理器 -->45. <property name="transactionManager" ref="transactionManager" />46. </bean>47.48.49. <bean id="hibernateGpsDevice"50. class="pass.gps.device.hibernate.HibernateGpsDevice">51. <property name="name">52. <value>hibernateDevice</value>53. </property>54. <property name="sessionFactory" ref="sessionFactory" />55. <property name="mirrorDataChanges">56. <value>true</value>57. </property>58. </bean>59. <!-- 同步更新索引 -->60. <bean id="compassGps" class="pass.gps.impl.SingleCompassGps"61. init-method="start" destroy-method="stop">62. <property name="compass" ref="compass" />63. <property name="gpsDevices">64. <list>65. <bean66. class="pass.spring.device.SpringSyncTransactionGpsDeviceWrapper">67. <property name="gpsDevice" ref="hibernateGpsDevice" />68. </bean>69. </list>70. </property>71. </bean>72.73.74. <bean id="compassTemplate"75. class="passTemplate">76. <property name="compass" ref="compass" />77. </bean>78.79. <!-- 定时重建索引(利用quartz)或随Spring ApplicationContext启动而重建索引 -->80. <bean id="compassIndexBuilder"81. class="passIndexBuilder"82. lazy-init="false">83. <property name="compassGps" ref="compassGps" />84. <property name="buildIndex" value="true" />85. <property name="lazyTime" value="10" />86. </bean>87.88.89.90.</beans>中间都有注解就不多解释了下面来编写dao及dao的实现以及severce层step5Java代码1.package com.v512.example.dao;2.3.import java.util.List;4.5.import com.v512.example.model.Product;6.7.public interface ProductDao {8. public void create(Product p);9. public Product getProduct(String id);10. public List getProducts();11. public void update(Product product);12. public void remove(String id);13.14.}Java代码1.package com.v512.example.dao.hibernate;2.3.import java.util.List;4.5.import com.v512.example.dao.ProductDao;6.import com.v512.example.model.Product;7.import org.springframework.orm.hibernate3.support.HibernateDaoSupport;8.public class ProductDaoHibernate extends HibernateDaoSupport implements ProductDao {9.10. public void create(Product p) {11. getHibernateTemplate().save(p);12.13. }14.15. public Product getProduct(String id) {16. return (Product)getHibernateTemplate().get(Product.class, id);17. }18.19. public List getProducts() {20. return getHibernateTemplate().find("from Product order by id desc");21. }22.23. public void remove(String id) {24. getHibernateTemplate().delete(getProduct(id));25.26. }27.28. public void update(Product product) {29. getHibernateTemplate().saveOrUpdate(product);30.31. }32.33.}serveceJava代码1.package com.v512.example.service;2.3.import java.util.List;4.5.import com.v512.example.model.Product;6.7.public interface ProductManager {8. public void insertProduct(Product p);9. public Product findProdcut(String id);10. public List searchProducts(String queryString);11.12.13.}servece的实现Java代码1.package com.v512.example.service.impl;2.3.import java.util.ArrayList;4.import java.util.List;5.6.import passHits;7.import passSession;8.import passTemplate;9.import passTransaction;10.11.import com.v512.example.dao.ProductDao;12.import com.v512.example.model.Product;13.import com.v512.example.service.ProductManager;14.import pass;15.public class ProductManagerImpl implements ProductManager {16. private ProductDao productDao;17. private CompassTemplate compassTemplate;18.19.20.21.22. public void setCompassTemplate(CompassTemplate compassTemplate){23. passTemplate=compassTemplate;24. }25.26. public void setProductDao(ProductDao productDao){27. this.productDao=productDao;28. }29.30. public Product findProdcut(String id) {31. return productDao.getProduct(id);32. }33.34. public void insertProduct(Product p) {35. productDao.create(p);36. }37.38. public List searchProducts(String queryString) {39. Compass compass = compassTemplate.getCompass();40. CompassSession session=compass.openSession();41. List list = new ArrayList();42. //这里不需要开启事务了,因为在调用这个方法之前就已经开启了事务43. CompassHits hits= session.queryBuilder().queryString("name:"+queryString).toQuery().hits();44. System.out.println("queryString:"+queryString);45. System.out.println("hits:"+hits.getLength());46. for(int i=0;i<hits.length();i++){47. Product hit=(Product)hits.data(i);48. list.add(hit);49. }50.51. return list;52. }53.54.55.56. public CompassTemplate getCompassTemplate() {57. return compassTemplate;58. }59.60.}所有的都做完了现在编写jsp页面step6insertProduct.jspJava代码1.<%@ page language="java" contentType="text/html; charset=UTF-8"2. pageEncoding="UTF-8"%>3.<%@ taglib prefix="s" uri="/struts-tags"%>4.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""/TR/html4/loose.dtd">5.<html>6.<head>7.<meta http-equiv="Content-Type" content="text/html; charset=utf-8">8.<link href="style/oa.css" rel="stylesheet" type="text/css"> 9.10.<title>添加信息</title>11.</head>12.<body>13.<center>14. <s:form action="insert.action" theme="simple">15.16.<TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0" style="width:300px;">17. <TBODY>18. <TR>19. <td align="center" class="tdEditTitle">添加商品名称</TD>20. </TR>21. <TR>22. <td>23.24.25.<table class="tableEdit" style="width:300px;" cellspacing="0" border="0" cellpadding="0">26. <tr>27. <td class="tdEditLabel" >商品名称</td>28. <td class="tdEditContent"><s:textfield name="product.name" label="名称" /></td>29. </tr>30.31. <tr>32. <td class="tdEditLabel" >商品品牌</td>33. <td class="tdEditContent"><s:textfield name="product.brand" label="品牌" /></td>34. </tr>35.36. <tr>37. <td class="tdEditLabel" >商品价格</td>38. <td class="tdEditContent"><s:textfield name="product.price" label="价格" /></td>39. </tr>40.41. <tr>42. <td class="tdEditLabel" >商品描述</td>43. <td class="tdEditContent"><s:textarea name="product.description" label="描述" />44. </td>45. </tr>46. <tr>47. <td> 48. </td>49. <td><s:submit/>50. <br></td>51. </tr>52.</table>53. </td>54. </TR>55. </TBODY>56.</TABLE>57.</s:form>58.</center>59.</body>60.</html>step7编写actionJava代码1.package com.v512.example.action;2.3.import java.util.List;4.5.import com.opensymphony.xwork2.ActionSupport;6.import com.v512.example.model.Product;7.import com.v512.example.service.ProductManager;8.import org.apache.struts2.ServletActionContext;9.10.public class ProductAction extends ActionSupport {11.12. private static final long serialVersionUID = 3795048906805728732L;13. private ProductManager productManager;14. private Product product;15. private String queryString;16.17. public void setQueryString(String queryString){18. this.queryString=queryString;19. }20.21. public Product getProduct() {22. return product;23. }24.25. public void setProduct(Product product) {26. this.product = product;27. }28.29. public void setProductManager(ProductManager productManager){30. this.productManager=productManager;31. }32.33. public String insert(){34. productManager.insertProduct(product);35. return SUCCESS;36. }37. public String search(){38. List results=productManager.searchProducts(queryString);39. System.out.println(results.size());40. ServletActionContext.getRequest().setAttribute("searchresults", results);41. return SUCCESS;42. }43.44.45.}step8关于Struts2的配置文件如下Java代码1.<?xml version="1.0" encoding="UTF-8" ?>2.<!DOCTYPE struts PUBLIC3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"4. "/dtds/struts-2.0.dtd">5.6.<struts>7. <constant name="struts.objectFactory" value="spring" />8.9. <include file="struts-default.xml"/>10.11. <package name="product" extends="struts-default"12. namespace="/product">13.14. <!-- 配置Struts2的Action,class值要与applicationContext*.xml中的id的值一致。
R语言丨diRblo:中文文本分析方便工具包chinese.misc简介(附文本样例)展开全文现在NLP技术那么发达了,各种工具那么NB了,可是用R做文本分析的人居然还得为如何读文件不乱码、如何分词、如何统计词频这样的事犯难,也是醉了。
如果老停留在这个水平上,那各位亲你们离自己整天挂在嘴边儿的大数据机器学习之类的基本上就无缘了。
所以希望大家能把更多精力放到算法上,而不是用在一些琐碎、浪费时间又极其恼人的事情上。
其实像文本清理这种活儿,基本上就应该是用鼠标点吧点吧就能自动完成的,若要还费半天劲的话纯属扯淡。
所以,chinese.misc这个R包就要来完成这个任务。
chinese.misc(目前为0.1.3版本)的功能极其简单,主要用于对中文文本进行数据清理工作,此外还包含另外一些实用的处理和分析功能。
在生成文档-词语矩阵的功能上,可以代替对中文不是太支持的tm包,特别是在减少乱码方面。
如果你现在还忙于看如何分词、如何删去停用词、如何计算词频之类的工作,那么这些都用不着看了,让我们把工作变得更无脑些!这个包的中文手册见https:///githubwwwjjj/chinese.misc。
不过,英文pdf 比中文说明详细多了。
chinese.misc的核心函数是corp_or_dtm,可直接从文件夹名/文件名/文本向量中生成文档-词语矩阵,并且自动或按使用者要求进行一些文本清理工作。
此外,软件包中dir_or_file、scancn、make_stoplist、slim_text 等函数都是在中文文本分析中比较实用的函数,可以帮助使用者减少很多麻烦。
在这里,我只展示一下这个包的少数功能,其它功能还请大家去看中文手册。
文本样例请到/s/1nuXLBg1下载,里边是30篇中纪委巡视报告。
如果你解压后文件数不对或是乱码,那几乎只可能是因为你正在使用MAC。
请尽量在WINDOWS上搞。
我们假设你解压后的文件路径是'f:/sample'。
Aceeditor中⽂⽂档介绍Ace是⼀个⽤JavaScript编写的可嵌⼊代码编辑器。
它与Sublime,Vim和TextMate等本地编辑器的功能和性能相匹配。
它可以轻松地嵌⼊任何⽹页和JavaScript应⽤程序中。
官⽹地址:Github:vue版:快速开始简单使⽤<div id="editor" style="height: 500px; width: 500px">some text</div><script src="src/ace.js" type="text/javascript" charset="utf-8"></script><script>var editor = ace.edit("editor");</script>设置主题和语⾔模式要更改主题,请为编辑器配置要使⽤的主题路径。
主题⽂件将按需加载:editor.setTheme("ace/theme/twilight");默认情况下,编辑器为纯⽂本模式。
但是,所有其他语⾔模式都可以作为单独的模块使⽤。
语⾔模式也将按需加载:editor.session.setMode("ace/mode/javascript");编辑器状态Ace将所有编辑器状态(选择,滚动位置等)保留在editor.session中, 这对于制作可切换式编辑器⾮常有⽤:var EditSession = require("ace/edit_session").EditSessionvar js = new EditSession("some js code")var css = new EditSession(["some", "css", "code here"])// 要将⽂档加载到编辑器中,只需这样调⽤editor.setSession(js)在项⽬中配置Ace// 将代码模式配置到ace选项ace.edit(element, {mode: "ace/mode/javascript",selectionStyle: "text"})// 使⽤setOptions⽅法⼀次设置多个选项editor.setOptions({autoScrollEditorIntoView: true,copyWithEmptySelection: true,});// 单独设置setOptions⽅法editor.setOption("mergeUndoDeltas", "always");// ⼀些选项也直接设置,例如:editor.setTheme(...)// 获取选项设置值editor.getOption("optionName");// 核⼼Ace组件包括(editor, session, renderer, mouseHandler)setOption(optionName, optionValue)setOptions({optionName : optionValue})getOption(optionName)getOptions()设置和获取内容:`editor.setValue("the new text here"); // 或 session.setValueeditor.getValue(); // 或 session.getValue获取选定的⽂本:editor.session.getTextRange(editor.getSelectionRange());在光标处插⼊:editor.insert("Something cool");获取当前光标所在的⾏和列:editor.selection.getCursor();转到某⼀⾏:editor.gotoLine(lineNumber);获取总⾏数:editor.session.getLength();设置默认标签⼤⼩:editor.getSession().setTabSize(4);使⽤软标签:editor.getSession().setUseSoftTabs(true);设置字体⼤⼩:document.getElementById('editor').style.fontSize='12px';切换⾃动换⾏:editor.getSession().setUseWrapMode(true);设置⾏⾼亮显⽰:editor.setHighlightActiveLine(false);设置打印边距可见性:editor.setShowPrintMargin(false);设置编辑器为只读:editor.setReadOnly(true); // false为可编辑窗⼝⾃适应编辑器仅在resize事件触发时时调整⾃⾝⼤⼩。
基于pgfSweave的漂亮中文动态文档
谢益辉
2010年2月8日
摘要
本文介绍了动态统计报告的原理以及R/Sweave的传统实现过程,重点引入pgfSweave包的说明
以及它与LYX的配合使用方法,最终我们可以在各种工具的配合下只使用一种前台编写出漂亮的动
态统计报告。
1引言
我们的工作总是在各种软件中换来换去,把A软件的结果导入B,把B的表格和图形贴入C,
数据在D目录下,程序在路人甲手中……这所有的工作都可以联合到一个工具中,就是Sweave。
Sweave本身的原理非常简单,它就是把做上特定标记的R代码用R跑一遍,把结果写回原代码所
在的地方。它之所以强大,基本上是因为R的强大(每个成功的奥特曼背后都有一个默默挨打
的小怪兽)。这个工作的可能性直接源于所有的工具都在和纯文本文件打交道:R代码是纯文本
(尽管它可以处理很多二进制文件)、LATEX文档是纯文本(尽管它可以嵌入二进制的图形等对
象)。
然而天外有天—pgfSweave包在动态文档的美观问题上提供了更惊艳的解决方案。它依
靠TikZ把Sweave生成的PDF图形转化为某种LATEX代码,即用LATEX代码重现原PDF图形。这样
一来,图中所有元素的外观便和文档能保持一致了,因为此时整个LATEX文档就彻底沦为文
本文件了。图中的数学公式也能搭车转为地道的LATEX数学公式,而不再依赖于生成它的工具
(如R)。还有一点副作用就是,中文也能搭车跟进来。
除了在美化图形方面的工作不够之外,Sweave的另一个不足之处就是不能缓存运行结
果,即:每次运行Sweave文档都要“从头再来”;cacheSweave包提出了解决方案,它能缓存
数据对象,但对图形对象依然无能为力,一幅PDF图形,怎么缓存?世上木有不可能的事情,
pgfSweave就在这个问题上继续迈进一步,使得图形也一样可以缓存,这样的话只要画图的R代
码没有变化,图形就不必重画,而是直接从缓存中读取即可,所以加快了编译的整体速度。
2了解pgfSweave包
确切地说,pgfSweave包主要仍然是基于Sweave的,只不过略微修改了一个driver函数而
已。它将Sweave的\includegraphics{*.pdf}换成了相应的\input{*.tikz}或其它格式,其实
1
3中文环境配置2
转换tikz格式的工作是tikzDevice包完成的。
首先,我们需要为pgfSweave包配置一个缓存路径1:
>setCacheDir("cache")
>pdf.options(family="GB1")
然后在确保LATEX宏包pgf已经安装(Rnw文档中要写明\usepackage{tikz}),并且Sweave.sty在TEX的
搜索路径中。如果你不知道这个文件在哪儿能找到,Windows用户可以运行:
>file.path(R.home(),"share","texmf")
[1]"C:\\PROGRA~1\\R/share/texmf"
pgfSweave包的主要函数就是pgfSweave(),它与Sweave()函数用法相似—提供一个*.Rnw文
件给它即可。如果需要编译为PDF,可以加上pdf=TRUE的参数。内部运行细节本文暂且忽
略。值得一提的是它对图形中数学公式的完美再现;请对比一下这个公式和图1中的数学公式:
Φ(x)=´x−∞1√2πexp(x2/2)dx,它们俩有差异么?貌似木有。
3中文环境配置
为了顺利使用中文和pgfSweave生成动态中文文档,我们有一些需要注意的地方。
3.1R语言
建议使用UTF-8编码,否则中文字符可能会被Sweave吃掉。设置UTF-8编码的语句为:
>options(encoding="UTF-8")
可以把它放在Rprofile.site文件中,以保证每次启动R之后默认的编码就是UTF-8,或者写
在Rnw文档的前面也可以。
3.2LATEX
据我所知,ctex宏包是最好的支持中文的LATEX宏包了,不用它用谁呢?
3.3LYX
一切发明创造都是为了偷懒,说得冠冕堂皇一些就是为了提高效率。懒人写LATEX文档自然
不会从\documentclass{xxx}写起,LYX便是偷懒的好帮手,不过从R到Sweave到LATEX到LYX这
一路配置还是有点麻烦的,没有付出哪有回报呢。
在LYX中需要做的事情是:写个使用ctex宏包的layout文件;建立从Sweave到LATEX的转换
器。
1
为了PDF图形设备能使用中文,此处也配置了pdf.options()选项。
3中文环境配置3
>set.seed(123)
>x<-rnorm(10)
>y<-x+rnorm(5,sd=0.25)
>model<-lm(y~x)
>par(mar=c(4,4,1,2))
>plot(x,y,pch=seq(x),ylab="$Y=\\beta_0+\\beta_1x+\\epsilon$")
>abline(model,col="red")
>legend("bottomright",legend=sprintf("$\\hat{Y}=%.2f+%.2fx$",
+coef(model)[1],coef(model)[2]),bty="n")
>legend("topleft",legend="$\\epsilon\\simN(0,\\sigma^2)$",
+bty="n")
>mtext("纯正\\LaTeX{}数学公式!",side=4)
>text(-0.5,1,paste("$\\Phi(x)=\\int_{-\\infty}^x\\frac{1}{\\sqrt{2\\pi}}",
+"\\exp(x^2/2)dx$"))
-1.0-0.50.00.51.01.5
-
1
.
0
-
0
.
5
0
.
0
0
.
5
1
.
0
1
.
5
2
.
0
x
Y
=
β
0
+
β
1
x
+
ˆ
Y=0.07+1.05x
∼N(0,σ2)
纯
正
L
A
T
E
X
数
学
公
式
!
Φ(x)=´x−∞1√2πexp(x2/2)dx
图1:一幅pgfSweave生成的图形,演示回归方程。动态生成x和y,建立回归模型,画出散点图
并在y轴上标注出理论模型Y=β0+β1x+;散点图的右下角写入一个回归方程的估计,系数
从模型中动态获取(保留两位小数);左上角写出误差项的假设。为了显摆真的很酷,画蛇添足
写了个标准正态分布函数。图右侧加入一行中文,有图有真相,中文真的是被支持的。为了显
摆LATEX真的很酷,画蛇添足写了个标准正态分布函数。图右侧加入一行中文,有图有真相,中
文真的是被支持的。
4小结4
4小结
pgfSweave,牛啊。