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

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


  /* (non-Javadoc)
   * @see junit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception {
    super.setUp();
    Model model = modelWithStatements("http://example.org/a dc:title 'Hello';" +
        "_:a http://xmlns.com/foaf/0.1/mbox http://example.org/b;" +
        "_:a rdfs:comment _:b");
    ReferenceGroundedDecomposition baseDec = new ReferenceGroundedDecompositionImpl(
        new ModelReferencingDecompositionImpl(JenaUtil.getGraphFromModel(model, true)));
    simpleFilterableDecomposition = new SimpleFilterableDecomposition(baseDec);
View Full Code Here


   */
  @Override
  protected void execute(Store store, GetCommandArguments arguments) {
    Source[] sources = arguments.getTrustedSources();
    Graph graph = store.getGraphOverTime(new HashSet<Source>(Arrays.asList(sources))).getGraph(new Date());
    Model model = JenaUtil.getModelFromGraph(graph);
    model.write(System.out);
  }
View Full Code Here

        QueryExecUtils.executeQuery(query, engine) ;
    }
   
    private static Model makeData()
    {
        Model model = ModelFactory.createDefaultModel() ;
        Resource r = model.createResource(NS+"r") ;
        Property p1 = model.createProperty(NS+"p1") ;
        Property p2 = model.createProperty(NS+"p2") ;
        model.add(r, p1, "xyz") ;
        model.add(r, p2, "abc") ;
        return model ;
    }
View Full Code Here

 
  public static void textToRDF(Resource subject, Seq seq, Node n, Context ctx) {
    String value = ((Text) n).getNodeValue();
    value = processWhitespace(n,value,null,ctx);
    if (!value.equals("")) {
      Model m = ctx.getModel();
      Literal lit = m.createLiteral(value);
      Statement stmt = m.createStatement(subject, RDF.value, lit);
      m.add(stmt);
      if (seq!=null) seq.add(stmt.createReifiedStatement());
    }
  }
View Full Code Here

  throws Exception {
   
    if (type!=null && type.equals(XSD_URI+"#anySimpleType")) type = RDFS.Literal.getURI();
     
    RDFDatatype dt = getDatatype(type);
    Model m = ctx.getModel();
    Statement stmt = null;
    RDFNode object = null;
    if (value==null) return true;

    // are all restrictions observed
    if (restrictions!=null)
      for (restriction r: restrictions)
        if (!r.isValid(value,type,ctx)) return false;
   
    simpleType s = ctx.getSimpleType(type);
    if (s!=null) return s.toRDF(subject,prop,node,value,seq,restrictions,ctx);
   
    // this may be an ID embedded in element content
    else if (type!=null && type.equals(XSD_URI+"#ID")) {
      String uri = subject.isAnon()?null:subject.getURI();
      String frag = addFragment(ctx.getBaseMap(), value).toString();
      if (frag.equals(uri)) return true;
      else object = m.createResource(frag)
    }   
    else if (type!=null && type.equals(XSD_URI+"#IDREF"))
      object = m.createResource(addFragment(ctx.getBaseMap(), value).toString());   
   
    else if (type!=null && type.equals(XSD_URI+"#IDREFS"))
      object = toRDFList(node,value,XSD.IDREF.getURI(),null,ctx);   

    else if (type!=null && type.equals(XSD_URI+"#ENTITIES"))
      object = toRDFList(node,value,XSD.ENTITY.getURI(),null,ctx);   

    else if (type!=null && (type.equals(XSD_URI+"#QName") || type.equals(XSD_URI+"#NOTATION")))
      object = m.createResource(expandQName(ctx.getDefaultNS(),value,node,ctx.getModel()));
   
    else if (type!=null && type.equals(XSD_URI+"#anyURI")) {
      URI uri = null;
      if (isValidURI(value)) uri = new URI(value);
      // it may be a relative URI
      // to avoid confusion it should begin with an initial name character
      // ensure it isn't a QName
      else if (value.indexOf(":")<0 && Character.isJavaIdentifierStart(value.charAt(0)))
        uri = resolveBase(node, new URI(value), ctx);   
      if (uri!=null) object = m.createTypedLiteral(uri.toString(),dt);
      else return false;
    }
    else if (type!=null && type.equals(XSD_URI+"#anySimpleType")) {
      object = m.createTypedLiteral(value==null?"":value,dt);
    }
    else if (RDFS.Literal.getURI().equals(type)) {
      object = m.createLiteral(value==null?"":value);
    }
    else if (value!=null && dt!=null && dt.isValid(value)) object = m.createTypedLiteral(value, dt);
    else object = m.createLiteral(value==null?"":value);
   
    if (object==null) return false;
    // if no property is supplied just add the value to the sequence/list
    if (prop==null && seq!=null) seq.add(object);
    else  {
      stmt = m.createStatement(subject, prop, object);
      m.add(stmt);
      // this can only be a sequence
      if (seq != null) seq.add(stmt.createReifiedStatement());     
    }   
    return true;   
  }
View Full Code Here

   \see http://www.w3.org/2001/XMLSchema-instance
   */
 
  static Statement toRDFStatement(Resource subject, Element elem, Property prop, String value, String type, Context ctx)
  throws Exception {
    Model m = ctx.getModel();

    if (value==null) {
      if (prop==RDF.value || type.endsWith("#ID")) return null;
      return m.createStatement(subject,prop,"");
    }
   
    Statement stmt = null;
    if (type.endsWith("#ID")) ;
    // ID is used to name the owning element - don't generate RDF
    // IDREF to globally named element
    else if (type.endsWith("#IDREF")) {
      Resource r = m.createResource(addFragment(ctx.getBaseMap(), value).toString());
      stmt = m.createStatement(subject,prop,r);
    }
    else if (type.endsWith("#IDREFS")) {
      Resource r = toRDFList(elem,value,XSD.IDREF.getURI(),null,ctx)
      stmt = m.createStatement(subject,prop,r);
    }
    else if (type.endsWith("#NMTOKENS")) {
      Resource r = toRDFList(elem,value,XSD.NMTOKEN.getURI(),null,ctx)
      stmt = m.createStatement(subject,prop,r);
    }
    else if (type.endsWith("#QName")) {
      RDFNode object = null;
      String name = XMLBean.expandQName(ctx.getDefaultNS(),null,value,elem,ctx.getModel());
      if (name!=null) {
        object = m.createResource(name);
        stmt = m.createStatement(subject,prop,object);
      }
    }
    else if (type.endsWith("#duration")) {
      // map duration into separate xs:yearMonthDuration and xs:dayTimeDuration
      // introduce intermediate bnode
      Resource object = m.createResource();
      stmt = m.createStatement(subject,prop,object);
      RDFNode ym = schema.yearMonthDuration(m,value);
      RDFNode dt = schema.dayTimeDuration(m,value);
      if (ym!=null) object.addProperty(RDF.value, ym);
      if (dt!=null) object.addProperty(RDF.value, dt);
    }
    else if (type.endsWith("#ENTITY")) {
      DocumentType doctype = elem.getOwnerDocument().getDoctype();
      Pattern entityPattern = Pattern.compile("<!ENTITY\\s+"+value+"\\s+'(.*)'>");
      Matcher match = entityPattern.matcher(doctype.getInternalSubset());
      if (match.find()) value = match.group(1);
      Literal l = m.createTypedLiteral(value,RDF.getURI()+"XMLLiteral");
      stmt = m.createStatement(subject,prop,l);
    }
    else { // schema datatype?
      RDFDatatype dt = getDatatype(type);
      if (dt != null) {
        Literal l = m.createTypedLiteral(processWhitespace(elem,value,type,ctx), dt);
        stmt = m.createStatement(subject,prop,l);
      }
    }
    return stmt;
  }
View Full Code Here

 
  /** map an array of attributes to RDF */
 
  public void toRDF(Resource subject, Node node, attribute[] attribute, Context ctx)
  throws Exception {
    Model m = subject.getModel();
    NamedNodeMap atts = node.getAttributes();
    // expand attribute names
    Map<String,Node> map = new HashMap<String,Node>();
    for (int i=0; i<atts.getLength(); i++) {
      // xmlns declaration
View Full Code Here

  /** incrementally add a value to an RDFList */
 
  public static RDFList toRDFList(Node node, String value, String itemType, RDFList list, Set<restriction> restrictions, Context ctx)
  throws Exception {
    RDFDatatype dt = getDatatype(itemType);
    Model m = ctx.getModel();
    RDFNode object = null;
   
    value = processWhitespace(node,value,itemType,ctx);

    if (itemType!=null && itemType.equals(XSD_URI+"#QName")) {
      String name = expandQName(ctx.getDefaultNS(),null,value,node,ctx.getModel());
      if (name==null) return null; // one bad value invalidates the entire list
      else object = m.createResource(name);
    }
    else if (itemType!=null && itemType.equals(XSD.IDREF.getURI())) {
      if (value.indexOf(':')>=0) return null; // avoid confusion with QNames
      object = ctx.getModel().createResource(addFragment(ctx.getBaseMap(), value).toString());
    }
   
    else if (itemType!=null && itemType.equals(XSD_URI+"#anyURI")) {
      URI uri = null;
      if (isValidURI(value)) uri = new URI(value);
      // ensure this isn't a QName
      else if (value.indexOf(":")<0 && Character.isJavaIdentifierStart(value.charAt(0)))
        uri = resolveBase(node, new URI(value), ctx);
      if (uri!=null) object = m.createTypedLiteral(uri.toString(),dt);
      else return null;
    }
    else if (value!=null && dt!=null && dt.isValid(value)) object = m.createTypedLiteral(value, dt);
    else object = m.createLiteral(value==null?"":value);
   
    // add the value to the list
    if (list.isEmpty()) list = ctx.getModel().createList(new RDFNode[] {object});
    else list.add(object);
    return list;   
View Full Code Here

  }

  // simple content only appears as a direct component of complexType so is not sequenced
  public boolean toRDF(Resource subject, Node node, Context ctx)
    throws Exception {
    Model model = subject.getModel();
    Element e = (Element) node;
    if (restriction != null)
      return restriction.toRDF(subject, node, getValue(e), RDF.value, null, null, ctx);
    else if (extension != null)
      return extension.toRDF(subject, e, RDF.value, null, ctx);
    else {// otherwise just add plain literal
      Literal l = model.createLiteral(schema.processWhitespace(node,getValue(e),null,ctx));
      subject.addProperty(RDF.value, l);
      return true;
    }     
  }
View Full Code Here

    {
      tables = new String[args.length - 5];
      for (int i = 5; i < args.length; i++) { tables[i - 5] = args[i]; }
    }
   
    Model configModel = process(server, driver, namespace, user, pass, tables, md);
   
    configModel.write(System.out, "N3");
  }
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.