📄 util.java
字号:
// The MIT License
//
// Copyright (c) 2004 Evren Sirin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
/*
* Created on Dec 27, 2003
*
*/
package org.mindswap.owl;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.mindswap.pellet.ATermUtils;
import aterm.ATermAppl;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.DAML_OIL;
import com.hp.hpl.jena.vocabulary.RDF;
/**
* @author Evren Sirin
*
*/
public class Util {
private static Model jena = ModelFactory.createDefaultModel();
public static List createList(Resource r) {
if(r.hasProperty(RDF.first))
return createList(r, RDF.first, RDF.rest, RDF.nil);
else if(r.hasProperty(DAML_OIL.first))
return createList(r, DAML_OIL.first, DAML_OIL.rest, DAML_OIL.nil);
return null;
}
public static List createList(Resource r, Property listFirst, Property listRest, Resource listNil) {
if(r.equals(listNil))
return new ArrayList();
Resource first = r.getProperty(listFirst).getResource();
Resource rest = r.getProperty(listRest).getResource();
if(first == null | rest == null)
return null;
List restList = createList(rest, listFirst, listRest, listNil);
restList.add(0, first);
return restList;
}
public static String getLocalName(URI uri) {
return getLocalName(uri.toString());
}
public static String getLocalName(String uri) {
int index = splitPos(uri);
if(index == -1) return null;
return uri.substring(index + 1);
}
public static String getNameSpace(URI uri) {
return getNameSpace(uri.toString());
}
public static String getNameSpace(String uri) {
int index = uri.indexOf("#");
if(index == -1) return null;
return uri.substring(0, index);
}
private static int splitPos(String uri) {
int pos = uri.indexOf("#");
if(pos == -1) pos = uri.lastIndexOf("/");
return pos;
}
public static URI toURI(String s) {
try {
return new URI(s.replaceAll(" ", "%20"));
} catch (URISyntaxException e) {
System.out.println("Invalid URI " + e);
throw new RuntimeException(e);
}
}
public static URI toURI(ATermAppl a) {
return toURI(a.getName());
}
public static URI toURI(Resource r) {
return toURI(r.getURI());
}
public static ATermAppl toATerm(URI uri) {
return ATermUtils.makeTermAppl(uri.toString());
}
public static Property toProperty(URI uri) {
return jena.createProperty(uri.toString());
}
public static Resource toResource(URI uri) {
return jena.createResource(uri.toString());
}
public static Resource toResource(String uri) {
return jena.createResource(uri);
}
public static URI standardURI(URI uri) {
if(!uri.toString().endsWith("#"))
uri = URI.create(uri.toString() + "#");
return uri;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -