注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿弥陀佛

街树飘影未见尘 潭月潜水了无声 般若观照心空静...

 
 
 

日志

 
 
关于我

一直从事气象预报、服务建模实践应用。 注重气象物理场、实况场、地理信息、本体知识库、分布式气象内容管理系统建立。 对Barnes客观分析, 小波,计算神经网络、信任传播、贝叶斯推理、专家系统、网络本体语言有一定体会。 一直使用Java、Delphi、Prolog、SQL编程。

网易考拉推荐

makewar  

2012-09-03 09:13:56|  分类: Ramadda |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package makewar;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;

public final class MakeWar extends Owl {

    private static String uri = "http://www.scnjw.com/idvimg/meteo_products.owl#";
    private PrintStream out;
    private static ArrayList<String> areaNms = new ArrayList<String>();
    private static ArrayList<String> areaClassNms = new ArrayList<String>();

    public MakeWar() throws FileNotFoundException, UnsupportedEncodingException {
        super(uri);
        OWLReasonerFactory reasonerFac = new Reasoner.ReasonerFactory();
        reasoner = reasonerFac.createReasoner(ont);
        getAreaNms("G_地理范围");
        //getAreaClassNms("G_地理范围");
    }

    /**
     * 为每个区域建立war包
     */
    public void make_wars() {
        for (int i = 0; i < areaNms.size(); i++) {
            String areaNm = areaNms.get(i);
            System.out.print(i + ":" + areaNm + " , ");
            repository(areaNm);
            if (i % 10 == 0) {
                System.out.println();
            }
        }
    }

    /**
     * 通过模板文件D:\ram_init\\repository.properties
     * 形成区域areaNm的D:\\ram_init\\repository\\WEB-INF\\repository.properties
     *
     * @param areaNm
     * @throws IOException
     */
    private void repository(String areaNm) {
        String  home="d:/ram_init/",lib_dir=home +"ramadda1.4/lib/",ramadda_jar_dir=lib_dir+ "ramadda/",
                temp_prop = home + "repository_templet.properties",
                dest_prop = ramadda_jar_dir + "org/ramadda/repository/resources/repository.properties",
                china = "china";
        String dest_jar = lib_dir + String.format("%s.jar", areaNm);
        try {
            File ff = new File(temp_prop);
            String str = FileUtils.readFileToString(ff);
            str = str.replaceAll(china, areaNm);
            File f = new File(dest_prop);
            f.delete();
            FileUtils.writeStringToFile(f, str);
        } catch (IOException ex) {
            Logger.getLogger(Meteo_Products.class.getName()).log(Level.SEVERE, null, ex);
        }
        File ramadda_jar_file = new File(dest_jar);
        if (ramadda_jar_file.exists()) {
            ramadda_jar_file.delete();
        }
        compress(ramadda_jar_dir,dest_jar);
    }
    private void compress(String srcdir, String zipFnm) {
        File zipFile = new File(zipFnm);
        File srcFile = new File(srcdir);
        Project prj = new Project();
        Zip zip = new Zip();
        zip.setProject(prj);
        zip.setDestFile(zipFile);
        FileSet fileSet = new FileSet();
        fileSet.setProject(prj);
        fileSet.setDir(srcFile);
        zip.addFileset(fileSet);
        zip.execute();
    }

    public void getAreaClassNms(String parent) {
        OWLClass thCls = fac.getOWLClass(":" + parent, pm);
        Set<OWLClassExpression> subClses0 = thCls.getSubClasses(ont);
        for (OWLClassExpression s0 : subClses0) {
            String id_name = splitClsName(s0.toString());
            areaClassNms.add(id_name);
            System.out.println(id_name);
            getAreaClassNms(id_name);
        }
    }

    public void getAreaNms(String parent) {
        OWLClass thCls = fac.getOWLClass(":" + parent, pm);
        Set<OWLClassExpression> subClses0 = thCls.getSubClasses(ont);
        for (OWLClassExpression s0 : subClses0) {
            String id_name = splitClsName(s0.toString());
            OWLClass c = s0.asOWLClass();
            String s = label(c);
            areaNms.add(s);
            areaClassNms.add(id_name);
            //System.out.println(s);
            getAreaNms(id_name);
        }
    }

    private String label(OWLClass clazz) {
        LabelExtractor le = new LabelExtractor();
        Set<OWLAnnotation> annotations = clazz.getAnnotations(ont);
        for (OWLAnnotation anno : annotations) {
            anno.accept(le);
        }
        if (le.getResult() != null) {
            return le.getResult().toString();
        } else {
            String[] ss = clazz.getIRI().toString().split("#");
            return ss[1];
        }
    }

    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
        MakeWar mp = new MakeWar();
        mp.make_wars();
    }
}
  评论这张
 
阅读(515)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017