Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.Model


   * @param username
   * @return
   */
  private Resource getUserResource(String username) {
    Graph graph  = configGOT.getGraph(new Date());
    Model model = JenaUtil.getModelFromGraph(graph);
    ResIterator resIter = model.listSubjectsWithProperty(ACCOUNTMANAGER.userName, username);
    if (resIter.hasNext()) {
      return resIter.nextResource();
    } else {
      return null;
    }
View Full Code Here


   * @see com.hp.hpl.jena.gvs.tool.GVSToolCommand#execute(com.hp.hpl.jena.gvs.Store, com.hp.hpl.jena.gvs.tool.GVSToolArguments)
   */
  @Override
  protected void execute(Store store, UpdateAssertCommandArguments arguments) {
    File uploadFile = arguments.getUploadFile();
    Model model = ModelFactory.createDefaultModel();
    String fileURLString;
    try {
      fileURLString = uploadFile.toURL().toString();
    } catch (MalformedURLException e1) {
      throw new RuntimeException(e1);
    }
    String lang = "RDF/XML";
    if (fileURLString.endsWith(".nt")) {
      lang = "N-TRIPLE";
    } else {
      if (fileURLString.endsWith(".n3") || fileURLString.endsWith(".turtle")) {
        lang = "N3";
      }
    }
    model.read(fileURLString, lang);
    Graph graph = JenaUtil.getGraphFromModel(model, true);
    Source identity = arguments.getIdentity();
    store.updateGraph(identity, new FCAGraphImpl(graph))
  }
View Full Code Here

  /**
   * @param string
   * @return
   */
  private static FCAGraph readGraph(String fileName) {
    Model model = ModelFactory.createDefaultModel();
    try {
      //model.read(new File(fileName).toURL().toString());
      model.read(MinimumFailingGraphDetector.class.getResource(fileName).toString());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return new FCAGraphImpl(model);

View Full Code Here

          super.setHeader(HeaderName.CONTENT_TYPE, "application/xml");
        }
        super.setBody(new MessageBody2Write() {
          //<?xml-stylesheet type="text/xsl" href="/stylesheets/topic"?>
          public void writeTo(WritableByteChannel out) throws IOException {
            Model model = JenaUtil.getModelFromGraph(graph);
            //TODO deliver other formats
            OutputStream outS = Channels.newOutputStream(out);
           
            if (stylesheet != null) {
              outS.write(("<?xml-stylesheet type=\"text/xsl\" href=\""+stylesheet+"\"?>\n").getBytes("utf-8"));
View Full Code Here

                addFunctionallyGroundedNode(fgNode)));
            return anonymousNode;
          }
        });
    File modelFile = new File(directory, "graph");
    Model model = JenaUtil.getModelFromGraph(naturalizedGraph);
    OutputStream modelOut = new FileOutputStream(modelFile);
    try {
      model.write(modelOut, "N-TRIPLE");
    } finally {
      modelOut.close();
    }
  }
View Full Code Here

   * @throws IOException
   */
  private void writeMetaInf(File directory, NamedNode node, Resource type,
      Object component) throws IOException {
    File metaInfFile = new File(directory, "meta-inf");
    Model metaInfModel = ModelFactory.createDefaultModel();
    Resource componentRes = metaInfModel.createResource(node.getURIRef());
    componentRes.addProperty(RDF.type, type);
    componentRes.addProperty(METAMODEL.hashCode, metaInfModel
        .createTypedLiteral(component.hashCode()));

    OutputStream metaInfOut = new FileOutputStream(metaInfFile);
    try {
      metaInfModel.write(metaInfOut, "N-TRIPLE");
    } finally {
      metaInfOut.close();
    }
    indexModel.add(metaInfModel);

View Full Code Here

      File directory = componentDirectory.getDirectory();
      directory.mkdirs();
      // writeMetaInf(directory, componentDirectory.getNode(),
      // METAMODEL.FunctionallyGroundedNode, functionallyGroundedNode);
      File metaInfFile = new File(directory, "meta-inf");
      Model metaInfModel = ModelFactory.createDefaultModel();
      Resource componentRes = metaInfModel
          .createResource(componentDirectory.getNode().getURIRef());
      componentRes.addProperty(RDF.type,
          METAMODEL.FunctionallyGroundedNode);
      componentRes.addProperty(METAMODEL.hashCode, metaInfModel
          .createTypedLiteral(functionallyGroundedNode.hashCode()));
      componentRes.addProperty(METAMODEL.strongHashCode, metaInfModel
          .createTypedLiteral(functionallyGroundedNode
              .strongHashCode()));
      for (NonTerminalMolecule molecule : functionallyGroundedNode
          .getGroundingMolecules()) {
        // storeNTMolecule doesn't add duplicate
        NamedNode moleculeName;
        try {
          moleculeName = storeNTMolecule(molecule);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
        componentRes.addProperty(METAMODEL.containsNonTerminalMolecule,
            metaInfModel.createResource(moleculeName.getURIRef()));
      }
      OutputStream metaInfOut = new FileOutputStream(metaInfFile);
      try {
        metaInfModel.write(metaInfOut, "N-TRIPLE");
      } finally {
        metaInfOut.close();
      }
      indexModel.add(metaInfModel);
      result = componentDirectory.node;
View Full Code Here

  /** checks identity of a graph retrieved using model.read()
   *
   * @throws Exception
   */
  public void testSimpleBody() throws Exception {
    Model model = modelWithStatements("_a dc:subject _b; _a rdfs:comment '���'");
    final Graph body = JenaUtil.getGraphFromModel(model, true);
    WebServer webServer = createServer().startNewWebServer(new GraphHandlerAdaptor(new GraphHandler() {

      public void handle(Request request, TypedResponse<Graph> response) throws HandlerException {
        response.setBody(body);
      }
    }), serverBinding);
   
    try {
      URL serverURL = new URL("http://"+serverBinding.getInetAddress().getHostAddress()+":"+serverBinding.getPort()+"/");
      Model retrievedModel = ModelFactory.createDefaultModel();
      retrievedModel.read(serverURL.toString());
      assertTrue(model.isIsomorphicWith(retrievedModel));
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    } finally {
      webServer.stop();
View Full Code Here

    public M readComponent(ComponentDirectory componentDirectory) {
      File modelFile = new File(componentDirectory.getDirectory(),
          "graph");
      Graph graph = cache.get(modelFile);
      if (graph == null) {
        Model model = ModelFactory.createDefaultModel();
        try {
          URL modelFileUrl = modelFile.toURL();
          if (log.isDebugEnabled()) {
            log.debug("reading: " + modelFileUrl.toString());
          }
          InputStream modelFileInputStream = modelFileUrl
              .openStream();
          try {
            model.read(modelFileInputStream, modelFileUrl
                .toString(), "N-TRIPLE");
          } finally {
            modelFileInputStream.close();
          }
View Full Code Here

  public NTFileGraph(File file)
      throws IOException {
    super(ReificationStyle.Standard);
    fileWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), "ascii"));
    if (file.exists()) {
      Model model = ModelFactory.createModelForGraph(this);
      new NonSkoNTripleReader().read(model, file.toURL().toString());
   
    created = true;
    log.debug("NTFileGraph created");
  }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.