示例#1
0
/** Converts {@link Pattern} to and from {@link ILiteral}. */
public class PatternConverter implements IConverter<Pattern> {
  private static final URI DATATYPE = URIs.createURI("java:" + Pattern.class.getName());

  @Inject private ILiteralFactory lf;

  private URI datatype = DATATYPE;

  public String getJavaClassName() {
    return Pattern.class.getName();
  }

  public URI getDatatype() {
    return datatype;
  }

  public void setDatatype(URI datatype) {
    this.datatype = datatype;
  }

  public Pattern deserialize(String label) {
    return Pattern.compile(label);
  }

  public ILiteral serialize(Pattern object) {
    return lf.createLiteral(object.toString(), datatype, null);
  }
}
示例#2
0
 @Override
 public URI getDatatype() {
   if (datatype == null) {
     if (literal.getDatatype() != null) {
       datatype = URIs.createURI(literal.getDatatype().toString());
     } else {
       datatype =
           literal.getLanguage() == null
               ? net.enilink.komma.core.Literal.TYPE_STRING
               : net.enilink.komma.core.Literal.TYPE_LANGSTRING;
     }
   }
   return datatype;
 }
示例#3
0
 @Override
 public URI getDefaultGraph() {
   return URIs.createURI("komma:default");
 }
示例#4
0
  protected void addBasicKnowledge(Repository repository) throws RepositoryException {
    String[] bundles = {"net.enilink.vocab.owl", "net.enilink.vocab.rdfs"};

    if (AbstractKommaPlugin.IS_ECLIPSE_RUNNING) {
      RepositoryConnection conn = null;
      try {
        conn = repository.getConnection();
        URI defaultGraph = getDefaultGraph();
        Resource[] contexts =
            defaultGraph == null
                ? new Resource[0]
                : new Resource[] {repository.getValueFactory().createURI(defaultGraph.toString())};
        if (!conn.hasStatement(null, null, null, false, contexts)) {
          for (String name : bundles) {
            URL url = Platform.getBundle(name).getResource("META-INF/org.openrdf.ontologies");
            if (url != null) {
              URL resolvedUrl = FileLocator.resolve(url);

              Properties properties = new Properties();
              InputStream in = resolvedUrl.openStream();
              properties.load(in);
              in.close();

              URI baseUri = URIs.createURI(url.toString()).trimSegments(1);
              for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                String file = entry.getKey().toString();
                if (file.contains("rdfs") && skipRdfsOnImport()) {
                  // skip RDF and RDFS schema
                  continue;
                }

                URI fileUri = URIs.createFileURI(file);
                fileUri = fileUri.resolve(baseUri);

                resolvedUrl = FileLocator.resolve(new URL(fileUri.toString()));
                if (resolvedUrl != null) {
                  in = resolvedUrl.openStream();
                  if (in != null && in.available() > 0) {
                    conn.add(in, "", RDFFormat.RDFXML, contexts);
                  }
                  if (in != null) {
                    in.close();
                  }
                }
              }
            }
          }
        }
      } catch (IOException e) {
        throw new KommaException("Cannot access RDF data", e);
      } catch (RepositoryException e) {
        throw new KommaException("Loading RDF failed", e);
      } catch (RDFParseException e) {
        throw new KommaException("Invalid RDF data", e);
      } finally {
        if (conn != null) {
          try {
            conn.close();
          } catch (RepositoryException e) {
            ModelPlugin.log(e);
          }
        }
      }
    }
  }
示例#5
0
文件: RESULTS.java 项目: komma/komma
public interface RESULTS {
  public static final URI TYPE_RESULT = URIs.createURI("komma:Result");
}