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

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


        return getLabels(conceptURI, FIELD_RELATED);
    }

    private void indexAnnotation(Resource skos_concept, Document conceptDoc,
            AnnotationProperty property, String field) {
        StmtIterator stmt_iter = skos_concept.listProperties(property);
        while (stmt_iter.hasNext()) {
            Literal labelLiteral = stmt_iter.nextStatement().getObject()
                    .as(Literal.class);
            String label = labelLiteral.getLexicalForm();
            String labelLang = labelLiteral.getLanguage();

            if (this.languages != null && !this.languages.contains(labelLang)) {
View Full Code Here


        }
    }

    private void indexObject(Resource skos_concept, Document conceptDoc,
            ObjectProperty property, String field) {
        StmtIterator stmt_iter = skos_concept.listProperties(property);
        while (stmt_iter.hasNext()) {
            RDFNode concept = stmt_iter.nextStatement().getObject();

            if (!concept.canAs(Resource.class)) {
                System.err.println("Error when indexing relationship of concept "
                        + skos_concept.getURI() + " .");
                continue;
View Full Code Here

    return triplesFromModel(model, tc, id);
  }

  public static int triplesFromModel(final Model model,
      final TripleConsumer tc, int id) {
    final StmtIterator sit = model.listStatements();
    final HashMap<Resource, Integer> blanknodeNames = new HashMap<Resource, Integer>();
    int number=0;
    while (sit.hasNext()) {
      final Statement s = sit.next();

      Literal subject, predicate, object;

      subject = printResource2Literal(s.getSubject(), blanknodeNames, id);
View Full Code Here

      String propertyUrl = line[0];
      String label = line[1];
      builder.append(label);
      builder.append(": ");
     
      StmtIterator iter = model.listStatements(null, model.getProperty(propertyUrl), (Resource)null);
     
      while (iter.hasNext()) {
        Statement stmt = iter.nextStatement();
        builder.append(stmt.getObject().asNode().getLiteralValue().toString());
      }
      builder.append("\n");     
    }
    logger.debug(builder.toString());   
View Full Code Here

                                      Model closureBlob, Collection<Resource> visited,
                                      ClosureTest test)
    {
        visited.add(r) ;

        StmtIterator sIter = r.listProperties() ;
        for ( ; sIter.hasNext() ; )
        {
            Statement stmt = sIter.nextStatement() ;
            closure(stmt, closureBlob, visited, test) ;
        }
    }
View Full Code Here

    }
 
    private void fixURI(String replacement)
      {
      // Replace all instances of statement predicate curr in input with replacement
      StmtIterator it = input.listStatements((Resource)null, input.createProperty( curr.asNode().getURI() ), (RDFNode)null);
      Model toDel = ModelFactory.createDefaultModel();
      Model toAdd = ModelFactory.createDefaultModel();
      while( it.hasNext() )
        {
        Statement torem = it.nextStatement();
        toDel.add( torem );
        toAdd.add( torem.getSubject(), toAdd.createProperty( replacement ), torem.getObject() );
        }
     
      // Replace all instances of statement object curr in input with replacement
      it = input.listStatements((Resource)null, (Property)null, input.createResource( curr.asNode().getURI() ));
      while( it.hasNext() )
        {
        Statement torem = it.nextStatement();
        toDel.add( torem );
        toAdd.add( torem.getSubject(), torem.getPredicate(), toAdd.createResource( replacement ) );
        }
     
      input.remove( toDel );
View Full Code Here

      };
      String[] children = dir.list( rdfxml );
      if ( children != null )
        namespaces = children.clone();
   
    StmtIterator it = repair.listStatements( (Resource)null, EYE.notFromSchema, (RDFNode)null );
    while ( it.hasNext() )
      {
      subject = it.nextStatement().getSubject();                
      curr = repair.listObjectsOfProperty( subject, EYE.onResource ).nextNode();
     
      boolean fixed = false;
     
      for ( int j = 0; j < namespaces.length; j++ )
        {
        Model currNS = ModelFactory.createDefaultModel().read( "file:" + nsBase + "/" + namespaces[j] );
        StmtIterator iter = currNS.listStatements( (Resource)null, RDF.type, (RDFNode)null );
        while( iter.hasNext() )
          {
          Resource thisSubj = iter.nextStatement().getSubject();
          if ( thisSubj.getLocalName() != null )
            if ( thisSubj.getLocalName().equals( curr.asNode().getLocalName() ) )
              {
                fixURI( thisSubj.getURI() );
                fixed = true;
View Full Code Here

          if ( largest < tested )
            largest = tested;
          }
        String decided = types.get( typeCount.indexOf( largest ) );
        // Now remove statements where their object is not of this type from this cardinality failure
        StmtIterator it1e = input.listStatements( input.createResource( repair.listObjectsOfProperty( curr, EYE.cardinalityFailure ).nextNode().asNode().getURI() ), input.createProperty( repair.listObjectsOfProperty( curr, EYE.onProperty ).nextNode().asNode().getURI() ), (RDFNode)null );
        Model remStat = ModelFactory.createDefaultModel();
        while ( it1e.hasNext() && numVals > maxCard ) // No sense removing more statements than we absolutely have to
          {
          Statement testing = it1e.nextStatement();
          String datatype = testing.getObject().asNode().getLiteralDatatypeURI();
          if ( datatype == null )
            datatype = defaultURI;
          if ( datatype != decided )
            {
View Full Code Here

    }
 
  private Model getLeaves( Model in )
    {
    Model out = ModelFactory.createDefaultModel();
    StmtIterator it = in.listStatements( null, RDFS.subClassOf, (RDFNode)null );
    int greatestDepth = 0;
    while ( it.hasNext() )
      {
      Statement curr = it.nextStatement();
      if ( in.listSubjectsWithProperty( RDFS.subClassOf, curr.getSubject() ).toList().size() <= 1 )
        {
        out.add( curr );
        out.add( input.listStatements( curr.getSubject(), null, (RDFNode)null ) );
        int temp = getDepthOf( curr.getSubject() );
        if ( temp > greatestDepth )
          greatestDepth = temp;
        }
      }
    it = out.listStatements();
    Model torem = ModelFactory.createDefaultModel();
    while ( it.hasNext() )
      {
      Statement curr = it.nextStatement();
      if ( getDepthOf( curr.getSubject() ) < greatestDepth )
        torem.add( curr );
      }
    out.remove( torem );
    return out;
View Full Code Here

    {
    this.input = m;
    this.repair = report;
    this.output = this.input;
   
    StmtIterator it = repair.listStatements(null, EYE.cardinalityFailure, (RDFNode)null);
   
    while ( it.hasNext() )
      {
      Statement currFailure = it.nextStatement();
      Resource subj = currFailure.getSubject();
      NodeIterator it2 = repair.listObjectsOfProperty( subj, EYE.repairType );
      while ( it2.hasNext() )
        {
        RDFNode curr = it2.nextNode();
        if ( curr.equals( EYE.decreaseNumProperties ) )
          {
          NodeIterator it3 = repair.listObjectsOfProperty( subj, EYE.statementRemoved );
          while ( it3.hasNext() )
            {
            Resource remStat = (Resource)it3.nextNode();
            Resource remS = (Resource)repair.listObjectsOfProperty( remStat, RDF.subject ).nextNode();
            Property remP = output.createProperty( repair.listObjectsOfProperty( remStat, RDF.predicate ).nextNode().asNode().getURI() );
            RDFNode remO = repair.listObjectsOfProperty( remStat, RDF.object ).nextNode();
            output.remove( remS, remP, remO );
            }
          }
        else if ( curr.equals( EYE.increaseNumProperties ) )
          {
          Resource addStat = (Resource)repair.listObjectsOfProperty( subj, EYE.statementAdded ).nextNode();
          Resource addS = (Resource)repair.listObjectsOfProperty( addStat, RDF.subject ).nextNode();
          Property addP = output.createProperty( repair.listObjectsOfProperty( addStat, RDF.predicate ).nextNode().asNode().getURI() );
          int target = Integer.parseInt( repair.listObjectsOfProperty( repair.createResource( repair.listObjectsOfProperty( subj, EYE.cardinality ).nextNode().asNode().getBlankNodeId() ), EYE.min ).nextNode().asNode().getLiteralLexicalForm() );
          int start = Integer.parseInt( repair.listObjectsOfProperty( subj, EYE.numValues ).nextNode().asNode().getLiteralLexicalForm() );
          for ( int i = start; i < target; i++ )
            output.add( addS, addP, output.createResource() );
          }
        else if ( curr.equals( EYE.increaseCardinality ) )
          {
          int target = Integer.parseInt( repair.listObjectsOfProperty( subj, EYE.max ).nextNode().asNode().getLiteralLexicalForm() );
          int minCard = Integer.parseInt( repair.listObjectsOfProperty( repair.createResource( repair.listObjectsOfProperty( subj, EYE.cardinality ).nextNode().asNode().getBlankNodeId() ), EYE.min ).nextNode().asNode().getLiteralLexicalForm() );
          Resource cName = output.createResource( ((OntModel)output).getBaseModel().listObjectsOfProperty( output.createResource( repair.listObjectsOfProperty( subj, EYE.onType).nextNode().asNode().getURI() ), RDFS.subClassOf ).nextNode().asNode().getBlankNodeId() );
          StmtIterator it3 = output.listStatements( cName, OWL.cardinality, (RDFNode)null );
          if ( it3.hasNext() )
            {
            output.remove( it3 );
            output.add( cName, OWL.minCardinality, output.createTypedLiteral( "" + minCard, "http://www.w3.org/2001/XMLSchema#integer" ) );
            }
          else
View Full Code Here

TOP

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

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.