1、出自《礼记·大学》
2、原文
《礼记·大学》:“古之欲明明德于天下者,先治其国;欲治其国者,先齐其家;欲齐其家者,先修其身;欲修其身者,先正其心;欲正其心者,先诚其意;欲诚其意者,先致其知,致知在格物。物格而后知至,知至而后意诚,意诚而后心正,心正而后身修,身修而后家齐,家齐而后国治,国治而后天下平。”
3、译文
古代那些要想在天下弘扬光明正大品德的人,先要治理好自己的国家;要想治理好自己的国家,先要管理好自己的家庭和家族;要想管理好自己的家庭和家族,先要修养自身的品性;要想修养自身的品性,先要端正自己的思想;要端正自己的思想,先要使自己的意念真诚;要想使自己的意念真诚,先要使自己获得知识,获得知识的途径在于认知研究万事万物。
通过对万事万物的认识研究,才能获得知识;获得知识后,意念才能真诚;意念真诚后,心思才能端正;心思端正后,才能修养品性;品性修养后,才能管理好家庭家族;家庭家族管理好了,才能治理好国家;治理好国家后天下才能太平。
扩展资料
1、“修身齐家治国平天下”是中国儒家思想的核心。养德修身是做人为官的基础,为官者如不讲究道德就没有资格领导管理民众,而官德最根本的就是为人民服务。
2、 “格物、致知、诚意、正心、修身、齐家、治国、平天下”后世称之为《大学》的“八条目”,这是实现“三纲领”的具体步骤。“八条目”的中心环节是修身,“自天子以至于庶人,壹是皆以修身为本”。对于培养目标和方法,《大学》反复强调的是个人的道德修养。大学的宗旨在于弘扬光明正大的品德,在于使人弃旧图新,在于使人达到最完善的境界。
3、“修身齐家治国平天下”可以视为对“大学之道”的概括,它也是儒家学说的精髓所在。儒家“修齐治平”之道也是自尧舜以来古圣先贤智慧的凝练与总结。因此它才能够在历代士人的心中深深扎根。无数的志士仁人都胸怀天下,心系苍生,他们有崇高的价值信念和高尚的理想追求,如北宋儒学家张载的“为天地立心、为生民立命、为往圣继绝学、为万世开太平”
没有反义词。
拼音:
xiū shēn qí jiā
解释:
提高自身修养,理好家政
出处:
元·无名氏《九世同居》第一折:“父亲,有甚么修身齐家的事,训教你儿者。”
语法:
修身齐家作谓语、宾语、定语;用于书面语。
示例:
宗璞《东藏记》:“大至治国兴邦,小至修身齐家,归根到底都得靠自己。”
出处:《礼记·大学》简译:意谓古代要向天下显示完美道德的人,首先要治理好他的国家,要治理好他的国家,先要治理好他的家庭;要治理好自己的家庭,首先要加强自己道德品质的修养;要加强自己道德品质的修养,首先要使自己心地纯正;要使自己成为心地纯正的人,首先要使自己的心意诚实;要使自己成为心意诚实的人,首先要使自己获得一定的知识;而获得知识在于把握事物的原理。
古之欲明明德于天下者,先治其国;欲治其国者,先齐其家,欲齐其家者,先修其身,欲修其身者,先正其心,欲正其心者,先诚其意,欲诚其意者,先致其知,致知在格物。
物格而后知至,知至而后意诚,意诚而后心正,心正而后身修,身修而后家齐,家齐而后国治,国治而后天下平。通过明确自己的信念和目标,让自己头脑清醒,明白是非曲直,努力在待人处事各方面在做到真诚,断恶修善,久而久之,变得有智慧有修养。家是国的缩影,经营好家庭的人一定能治理好国家,也一定能协助国家天下太平。
1、句意是:先修养品性,才能管理家庭,才能治理国家,才能使天下太平。
2、这句话出自于《礼记·大学》,原文如下:
古之欲明明德于天下者,先治其国;欲治其国者,先齐其家;欲齐其家者,先修其身;欲修其身者,先正其心;欲正其心者,先诚其意;欲诚其意者,先致其知,致知在格物。
物格而后知至,知至而后意诚,意诚而后心正,心正而后身修,身修而后家齐,家齐而后国治,国治而后天下平。
原文白话翻译
古代那些要想在天下弘扬光明正大品德的人,先要治理好自己的国家;要想治理好自己的国家,先要管理好自己的家庭和家族;要想管理好自己的家庭和家族,先要修养自身的品性。
要想修养自身的品性,先要端正自己的思想;要端正自己的思想,先要使自己的意念真诚;要想使自己的意念真诚,先要使自己获得知识,获得知识的途径在于认知研究万事万物。
通过对万事万物的认识研究,才能获得知识;获得知识后,意念才能真诚;意念真诚后,心思才能端正;心思端正后,才能修养品性;品性修养后,才能管理好家庭家族;家庭家族管理好了,才能治理好国家;治理好国家后天下才能太平。
对天下、国、家的划分如下:
周王室→王、天子→天下
↓↓
诸侯→公→→→国
↓↓
家族→卿、大夫→→家、宗族
有了对家国天下的认识,对自己的发展方向就是“修身齐家治国平天下”。修身具体来讲就是一个人要饱读诗书、道德高尚、有一技之长。齐家就是管理好一个家族、宗族,而不是具体的某一个人的家庭。
治国就是治理好一个小小的诸侯国,而不是我们现代意义的国家。要知道,古代的诸侯国是要对周王室负责的,也就是我们平时所说的"邦"。平天下就是安抚天下黎民百姓,使他们能够丰衣足食、安居乐业,而不是用武力平定天下。
意思是:要使美德彰明于天下的人,先治理好他的国家;要治理好国家的人,要先整顿好自己的家;要整顿好家的人,要先进行自我修养;要进行自我修养的人,要先端正他的思想,思想端正了,然后自我修养完善;自我修养完善了,然后家庭整顿有序;家庭整顿好了,然后国家安定繁荣;国家安定繁荣了,然后天下太平。
先修养品性,才能管理家庭,才能治理国家,才能使天下太平
出处:《礼记·大学》。相传为孔子弟子曾参(前505~前434)所作。
原文:
古之欲明明德于天下者,先治其国;欲治其国者,先齐其家;欲齐其家者,先修其身;欲修其身者,先正其心;欲正其心者,先诚其意;欲诚其意者,先致其知,致知在格物。物格而后知至,知至而后意诚,意诚而后心正,心正而后身修,身修而后家齐,家齐而后国治,国治而后天下平。
白话译文:
古代那些要想在天下弘扬光明正大品德的人,先要治理好自己的国家;要想治理好自己的国家,先要管理好自己的家庭和家族;要想管理好自己的家庭和家族,先要修养自身的品性;
要想修养自身的品性,先要端正自己的思想;要端正自己的思想,先要使自己的意念真诚;要想使自己的意念真诚,先要使自己获得知识,获得知识的途径在于认知研究万事万物。
通过对万事万物的认识研究,才能获得知识;获得知识后,意念才能真诚;意念真诚后,心思才能端正;心思端正后,才能修养品性;品性修养后,才能管理好家庭家族;家庭家族管理好了,才能治理好国家;治理好国家后天下才能太平。
1、做人要做老实(遵纪守法)、诚实(表里如一)、善良人,多做好事,终有好事。
2、族内子孙人等,妄作非为,有干名教者,不待鸣官,祠内先行整治。
3、粥一饭,当思来处不易;半丝半缕,恒念物力维艰。
4、重道德修养,严情操品性;扶正义,斥邪恶。
5、欲高门第须为善,要好儿孙必读书。
6、有百世之德者,必有百世之子孙保之;有十世之德者,就有十世的子孙保之;如果是斩焉无后者,那是德至薄也。
7、一粥一饭,当思来之不易;半丝半缕,恒念物力维艰。
8、一身能勤能敬,虽愚人亦有贤智风味。
9、一戒是(晚)起;二戒懒惰;三戒奢华;四戒骄傲。既守四戒,又须规以四宜:一宜勤读;二宜敬师;三宜爱众;四宜慎食。
10、学生要三勤:手勤、脑勤、读书勤。
之前看了Mahout官方示例 20news 的调用实现;于是想根据示例的流程实现其他例子。网上看到了一个关于天气适不适合打羽毛球的例子。
训练数据:
Day Outlook Temperature Humidity Wind PlayTennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D7 Overcast Cool Normal Strong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
D12 Overcast Mild High Strong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Strong No
检测数据:
sunny,hot,high,weak
结果:
Yes=》 0.007039
No=》 0.027418
于是使用Java代码调用Mahout的工具类实现分类。
基本思想:
1. 构造分类数据。
2. 使用Mahout工具类进行训练,得到训练模型。
3。将要检测数据转换成vector数据。
4. 分类器对vector数据进行分类。
接下来贴下我的代码实现=》
1. 构造分类数据:
在hdfs主要创建一个文件夹路径 /zhoujainfeng/playtennis/input 并将分类文件夹 no 和 yes 的数据传到hdfs上面。
数据文件格式,如D1文件内容: Sunny Hot High Weak
2. 使用Mahout工具类进行训练,得到训练模型。
3。将要检测数据转换成vector数据。
4. 分类器对vector数据进行分类。
这三步,代码我就一次全贴出来;主要是两个类 PlayTennis1 和 BayesCheckData = =》
package myTesting.bayes;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.classifier.naivebayes.training.TrainNaiveBayesJob;
import org.apache.mahout.text.SequenceFilesFromDirectory;
import org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles;
public class PlayTennis1 {
private static final String WORK_DIR = "hdfs://192.168.9.72:9000/zhoujianfeng/playtennis";
/*
* 测试代码
*/
public static void main(String[] args) {
//将训练数据转换成 vector数据
makeTrainVector();
//产生训练模型
makeModel(false);
//测试检测数据
BayesCheckData.printResult();
}
public static void makeCheckVector(){
//将测试数据转换成序列化文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"testinput";
String output = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean参数是,是否递归删除的意思
fs.delete(out, true);
}
SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();
String[] params = new String[]{"-i",input,"-o",output,"-ow"};
ToolRunner.run(sffd, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("文件序列化失败!");
System.exit(1);
}
//将序列化文件转换成向量文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";
String output = WORK_DIR+Path.SEPARATOR+"tennis-test-vectors";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean参数是,是否递归删除的意思
fs.delete(out, true);
}
SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();
String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};
ToolRunner.run(svfsf, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("序列化文件转换成向量失败!");
System.out.println(2);
}
}
public static void makeTrainVector(){
//将测试数据转换成序列化文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"input";
String output = WORK_DIR+Path.SEPARATOR+"tennis-seq";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean参数是,是否递归删除的意思
fs.delete(out, true);
}
SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();
String[] params = new String[]{"-i",input,"-o",output,"-ow"};
ToolRunner.run(sffd, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("文件序列化失败!");
System.exit(1);
}
//将序列化文件转换成向量文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-seq";
String output = WORK_DIR+Path.SEPARATOR+"tennis-vectors";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean参数是,是否递归删除的意思
fs.delete(out, true);
}
SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();
String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};
ToolRunner.run(svfsf, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("序列化文件转换成向量失败!");
System.out.println(2);
}
}
public static void makeModel(boolean completelyNB){
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-vectors"+Path.SEPARATOR+"tfidf-vectors";
String model = WORK_DIR+Path.SEPARATOR+"model";
String labelindex = WORK_DIR+Path.SEPARATOR+"labelindex";
Path in = new Path(input);
Path out = new Path(model);
Path label = new Path(labelindex);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean参数是,是否递归删除的意思
fs.delete(out, true);
}
if(fs.exists(label)){
//boolean参数是,是否递归删除的意思
fs.delete(label, true);
}
TrainNaiveBayesJob tnbj = new TrainNaiveBayesJob();
String[] params =null;
if(completelyNB){
params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow","-c"};
}else{
params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow"};
}
ToolRunner.run(tnbj, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("生成训练模型失败!");
System.exit(3);
}
}
}
package myTesting.bayes;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.mahout.classifier.naivebayes.BayesUtils;
import org.apache.mahout.classifier.naivebayes.NaiveBayesModel;
import org.apache.mahout.classifier.naivebayes.StandardNaiveBayesClassifier;
import org.apache.mahout.common.Pair;
import org.apache.mahout.common.iterator.sequencefile.PathType;
import org.apache.mahout.common.iterator.sequencefile.SequenceFileDirIterable;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.Vector.Element;
import org.apache.mahout.vectorizer.TFIDF;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Multiset;
public class BayesCheckData {
private static StandardNaiveBayesClassifier classifier;
private static Map<String, Integer> dictionary;
private static Map<Integer, Long> documentFrequency;
private static Map<Integer, String> labelIndex;
public void init(Configuration conf){
try {
String modelPath = "/zhoujianfeng/playtennis/model";
String dictionaryPath = "/zhoujianfeng/playtennis/tennis-vectors/dictionary.file-0";
String documentFrequencyPath = "/zhoujianfeng/playtennis/tennis-vectors/df-count";
String labelIndexPath = "/zhoujianfeng/playtennis/labelindex";
dictionary = readDictionnary(conf, new Path(dictionaryPath));
documentFrequency = readDocumentFrequency(conf, new Path(documentFrequencyPath));
labelIndex = BayesUtils.readLabelIndex(conf, new Path(labelIndexPath));
NaiveBayesModel model = NaiveBayesModel.materialize(new Path(modelPath), conf);
classifier = new StandardNaiveBayesClassifier(model);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("检测数据构造成vectors初始化时报错。。。。");
System.exit(4);
}
}
/**
* 加载字典文件,Key: TermValue; Value:TermID
* @param conf
* @param dictionnaryDir
* @return
*/
private static Map<String, Integer> readDictionnary(Configuration conf, Path dictionnaryDir) {
Map<String, Integer> dictionnary = new HashMap<String, Integer>();
PathFilter filter = new PathFilter() {
@Override
public boolean accept(Path path) {
String name = path.getName();
return name.startsWith("dictionary.file");
}
};
for (Pair<Text, IntWritable> pair : new SequenceFileDirIterable<Text, IntWritable>(dictionnaryDir, PathType.LIST, filter, conf)) {
dictionnary.put(pair.getFirst().toString(), pair.getSecond().get());
}
return dictionnary;
}
/**
* 加载df-count目录下TermDoc频率文件,Key: TermID; Value:DocFreq
* @param conf
* @param dictionnaryDir
* @return
*/
private static Map<Integer, Long> readDocumentFrequency(Configuration conf, Path documentFrequencyDir) {
Map<Integer, Long> documentFrequency = new HashMap<Integer, Long>();
PathFilter filter = new PathFilter() {
@Override
public boolean accept(Path path) {
return path.getName().startsWith("part-r");
}
};
for (Pair<IntWritable, LongWritable> pair : new SequenceFileDirIterable<IntWritable, LongWritable>(documentFrequencyDir, PathType.LIST, filter, conf)) {
documentFrequency.put(pair.getFirst().get(), pair.getSecond().get());
}
return documentFrequency;
}
public static String getCheckResult(){
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String classify = "NaN";
BayesCheckData cdv = new BayesCheckData();
cdv.init(conf);
System.out.println("init done...............");
Vector vector = new RandomAccessSparseVector(10000);
TFIDF tfidf = new TFIDF();
//sunny,hot,high,weak
Multiset<String> words = ConcurrentHashMultiset.create();
words.add("sunny",1);
words.add("hot",1);
words.add("high",1);
words.add("weak",1);
int documentCount = documentFrequency.get(-1).intValue(); // key=-1时表示总文档数
for (Multiset.Entry<String> entry : words.entrySet()) {
String word = entry.getElement();
int count = entry.getCount();
Integer wordId = dictionary.get(word); // 需要从dictionary.file-0文件(tf-vector)下得到wordID,
if (StringUtils.isEmpty(wordId.toString())){
continue;
}
if (documentFrequency.get(wordId) == null){
continue;
}
Long freq = documentFrequency.get(wordId);
double tfIdfValue = tfidf.calculate(count, freq.intValue(), 1, documentCount);
vector.setQuick(wordId, tfIdfValue);
}
// 利用贝叶斯算法开始分类,并提取得分最好的分类label
Vector resultVector = classifier.classifyFull(vector);
double bestScore = -Double.MAX_VALUE;
int bestCategoryId = -1;
for(Element element: resultVector.all()) {
int categoryId = element.index();
double score = element.get();
System.out.println("categoryId:"+categoryId+" score:"+score);
if (score > bestScore) {
bestScore = score;
bestCategoryId = categoryId;
}
}
classify = labelIndex.get(bestCategoryId)+"(categoryId="+bestCategoryId+")";
return classify;
}
public static void printResult(){
System.out.println("检测所属类别是:"+getCheckResult());
}
}
显示全部
收起