我想知道如何获得WEKA 文件的语法高亮.这是一个用来分析大数据的工具。
在 notepad++ 中,这是 arff 文件如何显示的示例语法高亮:
我开始代码在这里并对其进行了修改,但目前还没有得到预期的结果。以下是我目前已经开始的工作:
\documentclass{book}
\usepackage{listings}
\usepackage{color}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{document}
\begin{lstlisting}[language=Python, caption=WEKA Code]
% Assignment for BIG DATA - FIT DATA
% Author: I AM
% email: [email protected]
% 9 attributes
% 188 instances
@relation FIT
@attribute NUMUORS real % Number of unique operators
@attribute NUMUANDS real % Number of unique operands
@attribute TOTOTORS real % Total number of operators
@attribute TOTOPANDS real % Total number of operands
@attribute VG real % McCabe's cyclomatic complexity
@attribute NLOGIC real % Number of logical operators
@attribute LOC real % Lines of code
@attribute ELOC real % Executable line of code
@attribute FAULTS real % Number of faults
@data
22,85,203,174,9,0,362,40,0
21,87,186,165,5,0,379,32,0
30,107,405,306,25,0,756,99,0
6,5,19,6,2,0,160,9,0
21,47,168,148,7,0,352,29,0
28,38,161,114,10,3,375,40,0
27,218,1522,1328,114,0,1026,310,0
\end{lstlisting}
\end{document}
答案1
这是一个开始。删除language=Python
,它与你突出显示的语法无关。现在你需要用 来定义你的注释样式
comment=[l]{\%},
说明该行后面的部分%
是注释,并将关键字设置为两个不同的类别:
keywords={@relation,@attribute,@data},
morekeywords=[2]{real,integer,numeric,string,date},
这样您就可以用不同的颜色突出显示它们。
\documentclass{book}
\usepackage{listings}
\usepackage{color}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{blue},
keywordstyle={[2]\color{magenta}},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
comment=[l]{\%},
keywords={@relation,@attribute,@data},
morekeywords=[2]{real,integer,numeric,string,date},
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{document}
\begin{lstlisting}[style=mystyle,caption=WEKA Code]
% Assignment for BIG DATA - FIT DATA
% Author: I AM
% email: [email protected]
% 9 attributes
% 188 instances
@relation FIT
@attribute NUMUORS real % Number of unique operators
@attribute NUMUANDS real % Number of unique operands
@attribute TOTOTORS real % Total number of operators
@attribute TOTOPANDS real % Total number of operands
@attribute VG real % McCabe's cyclomatic complexity
@attribute NLOGIC real % Number of logical operators
@attribute LOC real % Lines of code
@attribute ELOC real % Executable line of code
@attribute FAULTS real % Number of faults
@data
22,85,203,174,9,0,362,40,0
21,87,186,165,5,0,379,32,0
30,107,405,306,25,0,756,99,0
6,5,19,6,2,0,160,9,0
21,47,168,148,7,0,352,29,0
28,38,161,114,10,3,375,40,0
27,218,1522,1328,114,0,1026,310,0
\end{lstlisting}
\end{document}
这涵盖了示例中的所有内容。它不会为数据中的逗号着色,但这可能行不通listings
,参见。如何在列表关键字中使用逗号?