Package org.openrdf.model

Examples of org.openrdf.model.ValueFactory


    }

    public void removeProjectFor( String groupId, String artifactId, String version, String artifactType )
        throws ProjectDaoException
    {
        ValueFactory valueFactory = rdfRepository.getValueFactory();
        URI id = valueFactory.createURI( groupId + ":" + artifactId + ":" + version + ":" + artifactType );
        try
        {
            repositoryConnection.remove( repositoryConnection.getStatements( id, null, null, true ) );
        }
        catch ( RepositoryException e )
View Full Code Here


    public Project getProjectFor( String groupId, String artifactId, String version, String artifactType,
                                  String publicKeyTokenId )
            throws ProjectDaoException {
        long startTime = System.currentTimeMillis();

        ValueFactory valueFactory = rdfRepository.getValueFactory();
     
        ProjectDependency project = new ProjectDependency();
        project.setArtifactId( artifactId );
        project.setGroupId( groupId );
        project.setVersion( version );
        project.setArtifactType( artifactType );
        project.setPublicKeyTokenId( publicKeyTokenId );

        TupleQueryResult result = null;

        try
        {
            TupleQuery tupleQuery = repositoryConnection.prepareTupleQuery( QueryLanguage.SERQL, projectQuery );
            tupleQuery.setBinding( ProjectUri.GROUP_ID.getObjectBinding(), valueFactory.createLiteral( groupId ) );
            tupleQuery.setBinding( ProjectUri.ARTIFACT_ID.getObjectBinding(), valueFactory.createLiteral( artifactId ) );
            tupleQuery.setBinding( ProjectUri.VERSION.getObjectBinding(), valueFactory.createLiteral( version ) );
            tupleQuery.setBinding( ProjectUri.ARTIFACT_TYPE.getObjectBinding(),
                                   valueFactory.createLiteral( artifactType ) );

            if ( publicKeyTokenId != null )
            {
                tupleQuery.setBinding( ProjectUri.CLASSIFIER.getObjectBinding(),
                                       valueFactory.createLiteral( publicKeyTokenId ) );
                project.setPublicKeyTokenId( publicKeyTokenId.replace( ":", "" ) );
            }

            result = tupleQuery.evaluate();
View Full Code Here

                + project.getVersion() );
        }

        Set<Artifact> artifactDependencies = new HashSet<Artifact>();

        ValueFactory valueFactory = rdfRepository.getValueFactory();
        URI id =
            valueFactory.createURI( project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()
                + ":" + project.getArtifactType() );
        URI groupId = valueFactory.createURI( ProjectUri.GROUP_ID.getPredicate() );
        URI artifactId = valueFactory.createURI( ProjectUri.ARTIFACT_ID.getPredicate() );
        URI version = valueFactory.createURI( ProjectUri.VERSION.getPredicate() );
        URI artifactType = valueFactory.createURI( ProjectUri.ARTIFACT_TYPE.getPredicate() );
        URI classifier = valueFactory.createURI( ProjectUri.CLASSIFIER.getPredicate() );
        URI isResolved = valueFactory.createURI( ProjectUri.IS_RESOLVED.getPredicate() );

        URI artifact = valueFactory.createURI( ProjectUri.ARTIFACT.getPredicate() );
        URI dependency = valueFactory.createURI( ProjectUri.DEPENDENCY.getPredicate() );
        URI parent = valueFactory.createURI( ProjectUri.PARENT.getPredicate() );

        Set<Model> modelDependencies = new HashSet<Model>();
        try
        {

            repositoryConnection.add( id, RDF.TYPE, artifact );
            repositoryConnection.add( id, groupId, valueFactory.createLiteral( project.getGroupId() ) );
            repositoryConnection.add( id, artifactId, valueFactory.createLiteral( project.getArtifactId() ) );
            repositoryConnection.add( id, version, valueFactory.createLiteral( project.getVersion() ) );
            repositoryConnection.add( id, artifactType, valueFactory.createLiteral( project.getArtifactType() ) );
            if ( project.getPublicKeyTokenId() != null )
            {
                URI classifierNode = valueFactory.createURI( project.getPublicKeyTokenId() + ":" );
                for ( Requirement requirement : project.getRequirements() )
                {
                    URI uri = valueFactory.createURI( requirement.getUri().toString() );
                    repositoryConnection.add( classifierNode, uri, valueFactory.createLiteral( requirement.getValue() ) );
                }

                repositoryConnection.add( id, classifier, classifierNode );
            }

            if ( project.getParentProject() != null )
            {
                Project parentProject = project.getParentProject();
                URI pid =
                    valueFactory.createURI( parentProject.getGroupId() + ":" + parentProject.getArtifactId() + ":"
                        + parentProject.getVersion() + ":" + project.getArtifactType() );
                repositoryConnection.add( id, parent, pid );
                artifactDependencies.addAll( storeProjectAndResolveDependencies( parentProject, null,
                                                                                 artifactRepositories, cache ) );
            }

            for ( ProjectDependency projectDependency : project.getProjectDependencies() )
            {
                Artifact assembly = createArtifactFrom( projectDependency, artifactFactory );

                snapshotVersion = null;
               
                if(!assembly.getFile().exists())
                {
                   
                    try
                    {                   
                     ArtifactRepository localArtifactRepository =
                        new DefaultArtifactRepository( "local", "file://" + localRepository,
                                                       new DefaultRepositoryLayout() );
                   
                    artifactResolver.resolve( assembly, artifactRepositories,
                                                      localArtifactRepository );
                    }
                    catch ( ArtifactNotFoundException e )
                    {
                        logger.warning( "NPANDAY-181-121:  Problem in resolving assembly: " + assembly.toString()
                        + ", Message = " + e.getMessage() );
                    }
                    catch ( ArtifactResolutionException e )
                    {
                        logger.warning( "NPANDAY-181-122: Problem in resolving assembly: " + assembly.toString()
                        + ", Message = " + e.getMessage() );
                    }
                }
               
                logger.finer( "NPANDAY-180-011: Project Dependency: Artifact ID = "
                    + projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
                    + ", Version = " + projectDependency.getVersion() + ", Artifact Type = "
                    + projectDependency.getArtifactType() );

                // If artifact has been deleted, then re-resolve
                if ( projectDependency.isResolved() && !ArtifactTypeHelper.isDotnetAnyGac( projectDependency.getArtifactType() ) )
                {
                    if ( projectDependency.getSystemPath() == null )
                    {
                        projectDependency.setSystemPath( generateDependencySystemPath( projectDependency ) );
                    }
                   
                    File dependencyFile = PathUtil.getDotNetArtifact( assembly , localRepository );
                   
                    if ( !dependencyFile.exists() )
                    {
                        projectDependency.setResolved( false );
                    }
                }

                // resolve system scope dependencies
                if ( projectDependency.getScope() != null && projectDependency.getScope().equals( "system" ) )
                {
                    if ( projectDependency.getSystemPath() == null )
                    {
                        throw new ProjectDaoException( "systemPath required for System Scoped dependencies " + "in Group ID = "
                            + projectDependency.getGroupId() + ", Artiract ID = " + projectDependency.getArtifactId() );
                    }

                    File f = new File( projectDependency.getSystemPath() );

                    if ( !f.exists() )
                    {
                        throw new IOException( "Dependency systemPath File not found:"
                            + projectDependency.getSystemPath() + "in Group ID = " + projectDependency.getGroupId()
                            + ", Artiract ID = " + projectDependency.getArtifactId() );
                    }

                    assembly.setFile( f );
                    assembly.setResolved( true );
                    artifactDependencies.add( assembly );

                    projectDependency.setResolved( true );

                    logger.finer( "NPANDAY-180-011.1: Project Dependency Resolved: Artifact ID = "
                        + projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
                        + ", Version = " + projectDependency.getVersion() + ", Scope = " + projectDependency.getScope()
                        + "SystemPath = " + projectDependency.getSystemPath()

                    );

                    continue;
                }

                // resolve com reference
                // flow:
                // 1. generate the interop dll in temp folder and resolve to that path during dependency resolution
                // 2. cut and paste the dll to buildDirectory and update the paths once we grab the reference of
                // MavenProject (CompilerContext.java)
                if ( projectDependency.getArtifactType().equals( "com_reference" ) )
                {
                    String tokenId = projectDependency.getPublicKeyTokenId();
                    String interopPath = generateInteropDll( projectDependency.getArtifactId(), tokenId );

                    File f = new File( interopPath );

                    if ( !f.exists() )
                    {
                        throw new IOException( "Dependency com_reference File not found:" + interopPath
                            + "in Group ID = " + projectDependency.getGroupId() + ", Artiract ID = "
                            + projectDependency.getArtifactId() );
                    }

                    assembly.setFile( f );
                    assembly.setResolved( true );
                    artifactDependencies.add( assembly );

                    projectDependency.setResolved( true );

                    logger.fine( "NPANDAY-180-011.1: Project Dependency Resolved: Artifact ID = "
                        + projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
                        + ", Version = " + projectDependency.getVersion() + ", Scope = " + projectDependency.getScope()
                        + "SystemPath = " + projectDependency.getSystemPath()

                    );

                    continue;
                }

                // resolve gac references
                // note: the old behavior of gac references, used to have system path properties in the pom of the
                // project
                // now we need to generate the system path of the gac references so we can use
                // System.getenv("SystemRoot")
                //we have already set file for the assembly above (in createArtifactFrom) so we do not need re-resovle it
                if ( !projectDependency.isResolved() )
                {
                    if ( ArtifactTypeHelper.isDotnetAnyGac( projectDependency.getArtifactType() ) )
                    {
                        try
                        {
                            if (assembly.getFile().exists())
                            {
                                projectDependency.setSystemPath( assembly.getFile().getAbsolutePath());
                                projectDependency.setResolved( true );
                                assembly.setResolved( true );
                            }
                            artifactDependencies.add( assembly );
                        }
                        catch ( ExceptionInInitializerError e )
                        {
                            logger.warning( "NPANDAY-180-516.82: Project Failed to Resolve Dependency: Artifact ID = "
                                + projectDependency.getArtifactId() + ", Group ID = " + projectDependency.getGroupId()
                                + ", Version = " + projectDependency.getVersion() + ", Scope = "
                                + projectDependency.getScope() + "SystemPath = " + projectDependency.getSystemPath() );
                        }
                    }
                    else
                    {
                        try
                        {
                            // re-resolve snapshots
                            if ( !assembly.isSnapshot() )
                            {
                                Project dep =
                                    this.getProjectFor( projectDependency.getGroupId(), projectDependency.getArtifactId(),
                                                        projectDependency.getVersion(),
                                                        projectDependency.getArtifactType(),
                                                        projectDependency.getPublicKeyTokenId() );
                                if ( dep.isResolved() )
                                {
                                    projectDependency = (ProjectDependency) dep;
                                    artifactDependencies.add( assembly );
                                    Set<Artifact> deps = this.storeProjectAndResolveDependencies( projectDependency,
                                                                                                  localRepository,
                                                                                                  artifactRepositories,
                                                                                                  cache );
                                    artifactDependencies.addAll( deps );
                                }
                            }
                        }
                        catch ( ProjectDaoException e )
                        {
                            logger.log( Level.WARNING, e.getMessage() );
                            // safe to ignore: dependency not found
                        }
                    }
                }

                if ( !projectDependency.isResolved() )
                {
                    logger.finest("NPANDAY-180-055: dependency:" + projectDependency.getClass());
                    logger.finest("NPANDAY-180-056: dependency:" + assembly.getClass());
                   
                    if ( assembly.getType().equals( "jar" ) )
                    {
                        logger.info( "Detected jar dependency - skipping: Artifact Dependency ID = "
                            + assembly.getArtifactId() );
                        continue;
                    }

                    ArtifactType type = ArtifactType.getArtifactTypeForPackagingName( assembly.getType() );

                    logger.finer( "NPANDAY-180-012: Resolving artifact for unresolved dependency: "
                                + assembly.getId());

                    ArtifactRepository localArtifactRepository =
                        new DefaultArtifactRepository( "local", "file://" + localRepository,
                                                       new DefaultRepositoryLayout() );
                    if ( !ArtifactTypeHelper.isDotnetExecutableConfig( type ))// TODO: Generalize to any attached artifact
                    {
                        logger.finest( "NPANDAY-180-016: set file....");
                   
                        Artifact pomArtifact =
                            artifactFactory.createProjectArtifact( projectDependency.getGroupId(),
                                                                   projectDependency.getArtifactId(),
                                                                   projectDependency.getVersion() );

                        try
                        {
                            artifactResolver.resolve( pomArtifact, artifactRepositories,
                                                      localArtifactRepository );

                            projectDependency.setResolved( true );                         
                           
                            logger.finer( "NPANDAY-180-024: resolving pom artifact: " + pomArtifact.toString() );
                            snapshotVersion = pomArtifact.getVersion();

                        }
                        catch ( ArtifactNotFoundException e )
                        {
                            logger.warning( "NPANDAY-180-025:  Problem in resolving pom artifact: " + pomArtifact.toString()
                                + ", Message = " + e.getMessage() );

                        }
                        catch ( ArtifactResolutionException e )
                        {
                            logger.warning( "NPANDAY-180-026: Problem in resolving pom artifact: " + pomArtifact.toString()
                                + ", Message = " + e.getMessage() );
                        }

                        if ( pomArtifact.getFile() != null && pomArtifact.getFile().exists() )
                        {
                            FileReader fileReader = new FileReader( pomArtifact.getFile() );

                            MavenXpp3Reader reader = new MavenXpp3Reader();
                            Model model;
                           
                            try
                            {
                                model = reader.read( fileReader ); // TODO: interpolate values
                            }
                            catch ( XmlPullParserException e )
                            {
                                throw new IOException( "NPANDAY-180-015: Unable to read model: Message = "
                                    + e.getMessage() + ", Path = " + pomArtifact.getFile().getAbsolutePath() );

                            }
                            catch ( EOFException e )
                            {
                                throw new IOException( "NPANDAY-180-016: Unable to read model: Message = "
                                    + e.getMessage() + ", Path = " + pomArtifact.getFile().getAbsolutePath() );
                            }

                            // small hack for not doing inheritence
                            String g = model.getGroupId();
                            if ( g == null )
                            {
                                g = model.getParent().getGroupId();
                            }
                            String v = model.getVersion();
                            if ( v == null )
                            {
                                v = model.getParent().getVersion();
                            }
                            if ( !( g.equals( projectDependency.getGroupId() )
                                && model.getArtifactId().equals( projectDependency.getArtifactId() ) && v.equals( projectDependency.getVersion() ) ) )
                            {
                                throw new ProjectDaoException(
                                                       "NPANDAY-180-017: Model parameters do not match project dependencies parameters: Model: "
                                                           + g + ":" + model.getArtifactId() + ":" + v + ", Project: "
                                                           + projectDependency.getGroupId() + ":"
                                                           + projectDependency.getArtifactId() + ":"
                                                           + projectDependency.getVersion() );
                            }
                            if( model.getArtifactId().equals( projectDependency.getArtifactId() ) && projectDependency.isResolved() )
                            {
                               modelDependencies.add( model );
                            }
                        }

                    }
                    logger.finest( "NPANDAY-180-019: set file...");
                    if ( snapshotVersion != null )
                    {
                        assembly.setVersion( snapshotVersion );
                    }

                    File dotnetFile = PathUtil.getDotNetArtifact( assembly , localRepository );
                   
                    logger.warning( "NPANDAY-180-018: Not found in local repository, now retrieving artifact from wagon:"
                            + assembly.getId()
                            + ", Failed Path Check = " + dotnetFile.getAbsolutePath());

                    if ( !ArtifactTypeHelper.isDotnetExecutableConfig( type ) || !dotnetFile.exists() )// TODO: Generalize to any attached artifact
                    {
                        try
                        {
                            artifactResolver.resolve( assembly, artifactRepositories,
                                                      localArtifactRepository );

                            projectDependency.setResolved( true );
                           
                            if ( assembly != null && assembly.getFile().exists() )
                            {
                                dotnetFile.getParentFile().mkdirs();
                                FileUtils.copyFile( assembly.getFile(), dotnetFile );
                                assembly.setFile( dotnetFile );
                            }
                        }
                        catch ( ArtifactNotFoundException e )
                        {
                            logger.log(Level.SEVERE, "NPANDAY-180-0201: Error resolving artifact. Reason:", e);
                            throw new ProjectDaoException(
                                                   "NPANDAY-180-020: Problem in resolving artifact: Artifact = "
                                                       + assembly.getId()
                                                       + ", Message = " + e.getMessage(), e );
                        }
                        catch ( ArtifactResolutionException e )
                        {
                            logger.log( Level.SEVERE, "NPANDAY-180-019: Problem in resolving artifact: Artifact = "
                                              + assembly.getId()
                                              + ", Message = " + e.getMessage(), e );
                            throw new ProjectDaoException(
                                                   "NPANDAY-180-019: Problem in resolving artifact: Artifact = "
                                                       + assembly.getId()
                                                       + ", Message = " + e.getMessage(), e );
                        }
                    }
                    artifactDependencies.add( assembly );
                }// end if dependency not resolved
                URI did =
                    valueFactory.createURI( projectDependency.getGroupId() + ":" + projectDependency.getArtifactId()
                        + ":" + projectDependency.getVersion() + ":" + projectDependency.getArtifactType() );
                repositoryConnection.add( did, RDF.TYPE, artifact );
                repositoryConnection.add( did, groupId, valueFactory.createLiteral( projectDependency.getGroupId() ) );
                repositoryConnection.add( did, artifactId,
                                          valueFactory.createLiteral( projectDependency.getArtifactId() ) );
                repositoryConnection.add( did, version, valueFactory.createLiteral( projectDependency.getVersion() ) );
                repositoryConnection.add( did, artifactType,
                                          valueFactory.createLiteral( projectDependency.getArtifactType() ) );
                if ( projectDependency.getPublicKeyTokenId() != null )
                {
                    repositoryConnection.add(
                                              did,
                                              classifier,
                                              valueFactory.createLiteral( projectDependency.getPublicKeyTokenId() + ":" ) );
                }
                repositoryConnection.add( id, dependency, did );

            }// end for
            repositoryConnection.add( id, isResolved, valueFactory.createLiteral( true ) );
            repositoryConnection.commit();
        }
        catch ( OpenRDFException e )
        {
            if ( repositoryConnection != null )
View Full Code Here

  }


  public static List<Statement> moleculeGraph2RDF(UGraph<String> graph, String moleculeID, boolean blankRoot) {
    List<Statement> moleculeRDF = new ArrayList<Statement>();
    ValueFactory factory = ValueFactoryImpl.getInstance();
    Map<Integer, BNode> nodeMap = new HashMap<Integer,BNode>();
    URI moleculeURI;
    if (blankRoot) {
      moleculeURI = factory.createURI(NAMESPACE, "moleculeInstance");
    } else {
      moleculeURI = factory.createURI(NAMESPACE, moleculeID);
    }
    URI partOfURI = factory.createURI(NAMESPACE, "partOf");
    URI hasAtomURI = factory.createURI(NAMESPACE, "hasAtom")
    URI bondURI = factory.createURI(NAMESPACE, "hasBond");
    moleculeRDF.add(factory.createStatement(moleculeURI, RDF.TYPE, factory.createURI(NAMESPACE, "Molecule")));

    for (UNode<String> node : graph.nodes()) {
      BNode bn = factory.createBNode(moleculeID + "_" + node.index());
      nodeMap.put(node.index(), bn);
      moleculeRDF.add(factory.createStatement(moleculeURI, hasAtomURI, bn));
      moleculeRDF.add(factory.createStatement(bn, partOfURI, moleculeURI));
      moleculeRDF.add(factory.createStatement(bn, RDF.TYPE, factory.createURI(NAMESPACE + "atom/", node.label())));
    }
    for (ULink<String> link : graph.links()) {
      moleculeRDF.add(factory.createStatement(nodeMap.get(link.first().index()), bondURI, nodeMap.get(link.second().index())));
      moleculeRDF.add(factory.createStatement(nodeMap.get(link.second().index()), bondURI, nodeMap.get(link.first().index())));
    }
    return moleculeRDF;
  }
View Full Code Here

    }
  }

 
  public void annotate(String label, int cluster) {
    ValueFactory f = conn.getValueFactory();
   
    Resource node = null;
    if(label.startsWith("http"))
      node = f.createURI(label);
    else
      return ; // we are not annotating literals
         
    URI pred = f.createURI("http://data2semantics.org/experiments/clusterAs");
    Literal val = f.createLiteral(cluster);
    try {
      conn.add(node,pred,val);
    } catch (RepositoryException e) {
      Global.log().warning("Failed to parse original RDF");
    }
View Full Code Here

  public Workflow workflow() {
    return workflow;
  }
 
  private void writePROV() throws IOException {
    ValueFactory factory = ValueFactoryImpl.getInstance();   
    Model stmts = new LinkedHashModel();
    FileInputStream fis = new FileInputStream(workflow.file());
    String workflowMD5sum = DigestUtils.md5Hex(fis);
    long currentTimeMilis = System.currentTimeMillis();
   
    // Define all the URI's that we are going to (re)use
    URI eURI = factory.createURI(PROV_NAMESPACE, "Entity");
    URI acURI = factory.createURI(PROV_NAMESPACE, "Activity");
    URI usedURI = factory.createURI(PROV_NAMESPACE, "used");
    URI wgbURI  = factory.createURI(PROV_NAMESPACE, "wasGeneratedBy");
    URI  genAtURI  = factory.createURI(PROV_NAMESPACE, "generatedAtTime");
    URI  startAtURI  = factory.createURI(PROV_NAMESPACE, "startedAtTime");
    URI  endAtURI  = factory.createURI(PROV_NAMESPACE, "endedAtTime");
   
    URI valueURI = factory.createURI(NAMESPACE, "value");
   
    URI agURI = factory.createURI(PROV_NAMESPACE, "Agent");
    URI watURI  = factory.createURI(PROV_NAMESPACE, "wasAttributedTo");
    URI wawURI  = factory.createURI(PROV_NAMESPACE, "wasAssociatedWith");
   
    URI planURI  = factory.createURI(PROV_NAMESPACE, "Plan");
    URI assoURI  = factory.createURI(PROV_NAMESPACE, "Association")
    URI qualAssoURI  = factory.createURI(PROV_NAMESPACE, "qualifiedAssociation")
   
    URI hadPlanURI  = factory.createURI(PROV_NAMESPACE, "hadPlan");
    URI hadAgentURI  = factory.createURI(PROV_NAMESPACE, "agent");
     
    URI platformURI = factory.createURI(NAMESPACE + "ducktape/", InetAddress.getLocalHost().getHostName() + "/" + Global.getSerialversionuid());
    URI workflowURI = factory.createURI(NAMESPACE + "workflow/", workflow.file().getAbsolutePath() + "/" + workflowMD5sum);
     
    // The software is the agent and the workflow is the plan
    stmts.add(factory.createStatement(platformURI, RDF.TYPE, agURI));
    stmts.add(factory.createStatement(workflowURI, RDF.TYPE, planURI));
   
    stmts.add(factory.createStatement(platformURI, RDFS.LABEL,
        Literals.createLiteral(factory, "ducktape on: " + InetAddress.getLocalHost().getHostName() + ", versionID: " + Global.getSerialversionuid())));
    stmts.add(factory.createStatement(workflowURI, RDFS.LABEL,
        Literals.createLiteral(factory, workflow.name() + ", date: " + new Date(workflow.file().lastModified()))));
   
 
   
    String moduleInstanceSumTimestamp = "module/instance/"+InetAddress.getLocalHost().getHostName()+"/"+workflowMD5sum+"/"+currentTimeMilis+"/";
    for (Module module : workflow.modules()) {
     
      for (ModuleInstance mi : module.instances()) {
        // Create provenance for the module (as an activity)
        URI miURI = factory.createURI(NAMESPACE + moduleInstanceSumTimestamp, module.name() + mi.moduleID());
        stmts.add(factory.createStatement(miURI, RDF.TYPE, acURI)); // Activity
        stmts.add(factory.createStatement(miURI, startAtURI, Literals.createLiteral(factory, new Date(mi.startTime())))); // Start time
        stmts.add(factory.createStatement(miURI, endAtURI, Literals.createLiteral(factory, new Date(mi.endTime())))); // end time     
        stmts.add(factory.createStatement(miURI, wawURI, platformURI)); // wasAssociatedWith
       
        // qualified Association
        BNode bn = factory.createBNode();
        stmts.add(factory.createStatement(bn, RDF.TYPE, assoURI));
        stmts.add(factory.createStatement(bn, hadPlanURI, workflowURI));
        stmts.add(factory.createStatement(bn, hadAgentURI, platformURI));
        stmts.add(factory.createStatement(miURI, qualAssoURI, bn));
       
        // Create provenance for the outputs (as entities)
        for (InstanceOutput io : mi.outputs()) {
          URI ioURI = factory.createURI(NAMESPACE + moduleInstanceSumTimestamp, module.name() + mi.moduleID() + "/output/" + io.name());
          stmts.add(factory.createStatement(ioURI, RDF.TYPE, eURI)); // entity
          stmts.add(factory.createStatement(ioURI, wgbURI, miURI)); // wasGeneratedBy
          stmts.add(factory.createStatement(ioURI, genAtURI, Literals.createLiteral(factory, new Date(io.creationTime())))); // generated at time
          stmts.add(factory.createStatement(ioURI, watURI, platformURI)); // wasAttributedTo
         
          // If we can create a literal of the value, save it and create a rdfs-label
          if (Literals.canCreateLiteral(io.value())) {
            stmts.add(factory.createStatement(ioURI, valueURI, Literals.createLiteral(factory, io.value())));
            stmts.add(factory.createStatement(ioURI, RDFS.LABEL, Literals.createLiteral(factory, io)));
          }
        }
       
        // Create provenance for the inputs (as entities)
        for (InstanceInput ii : mi.inputs()) {
          URI iiURI = null;
         
          if (ii.instanceOutput() != null) {
            iiURI = factory.createURI(NAMESPACE + moduleInstanceSumTimestamp, ii.instanceOutput().module().name()
                + ii.instanceOutput().instance().moduleID() + "/output/" + ii.name());
          } else {
            iiURI = factory.createURI(NAMESPACE + moduleInstanceSumTimestamp, module.name() + mi.moduleID()
                + "/input/" + ii.name());
           
            // If we can create a literal
            if (Literals.canCreateLiteral(ii.value())) {
              stmts.add(factory.createStatement(iiURI, valueURI, Literals.createLiteral(factory, ii.value())));
              stmts.add(factory.createStatement(iiURI, RDFS.LABEL, Literals.createLiteral(factory, ii)));
            }     
          }
             
          stmts.add(factory.createStatement(iiURI, RDF.TYPE, eURI)); // entity
          stmts.add(factory.createStatement(miURI, usedURI, iiURI)); // used         
        }
      }
    }
   
    File file = new File(root, PROV_FILE);
View Full Code Here

        loader.shutdown();
    }

   
    private void testRepoContent(RepositoryConnection con) throws RepositoryException {
        final ValueFactory vf = con.getValueFactory();
        assertThat(con.size(), CoreMatchers.equalTo(new Long(34)));
        assertTrue(con.hasStatement(vf.createURI("http://localhost:8080/LMF/resource/hans_meier"), RDF.TYPE, FOAF.Person, true));
        assertTrue(con.hasStatement(vf.createURI("http://localhost:8080/LMF/resource/sepp_huber"), RDF.TYPE, FOAF.Person, true));
        assertTrue(con.hasStatement(vf.createURI("http://localhost:8080/LMF/resource/anna_schmidt"), RDF.TYPE, FOAF.Person, true));
    }
View Full Code Here

    // Note: this test will always pass as long as we're using ValueFactoryImpl

    @Test
    public void testCreateLiteralsThroughValueFactory() throws Exception {
        Literal l;
        ValueFactory vf = sail.getValueFactory();

        l = vf.createLiteral("a plain literal");
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("a plain literal", l.getLabel());
        assertNull(l.getDatatype());
        l = vf.createLiteral("auf Deutsch, bitte", "de");
        assertNotNull(l);
        assertEquals("de", l.getLanguage());
        assertEquals("auf Deutsch, bitte", l.getLabel());
        assertNull(l.getDatatype());

        // Test data-typed createLiteral methods
        l = vf.createLiteral("foo", XMLSchema.STRING);
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("foo", l.getLabel());
        assertEquals(XMLSchema.STRING, l.getDatatype());
        l = vf.createLiteral(42);
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("42", l.getLabel());
        assertEquals(42, l.intValue());
        assertEquals(XMLSchema.INT, l.getDatatype());
        l = vf.createLiteral(42l);
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("42", l.getLabel());
        assertEquals(42l, l.longValue());
        assertEquals(XMLSchema.LONG, l.getDatatype());
        l = vf.createLiteral((short) 42);
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("42", l.getLabel());
        assertEquals((short) 42, l.shortValue());
        assertEquals(XMLSchema.SHORT, l.getDatatype());
        l = vf.createLiteral(true);
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("true", l.getLabel());
        assertEquals(true, l.booleanValue());
        assertEquals(XMLSchema.BOOLEAN, l.getDatatype());
        l = vf.createLiteral((byte) 'c');
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("99", l.getLabel());
        assertEquals((byte) 'c', l.byteValue());
        assertEquals(XMLSchema.BYTE, l.getDatatype());
        XMLGregorianCalendar calendar = XMLDatatypeUtil.parseCalendar("2002-10-10T12:00:00-05:00");
        l = vf.createLiteral(calendar);
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("2002-10-10T12:00:00-05:00", l.getLabel());
        assertEquals(calendar, l.calendarValue());
        assertEquals(XMLSchema.DATETIME, l.getDatatype());
View Full Code Here

    @Test
    public void testGetLiteralsFromTripleStore() throws Exception {
        Literal l;
        String prefix = "urn:com.tinkerpop.blueprints.pgm.oupls.sail.test/";
        XMLGregorianCalendar calendar;
        ValueFactory vf = sail.getValueFactory();
        SailConnection sc = sail.getConnection();

        // Get an actual plain literal from the triple store.
        URI ford = vf.createURI(prefix + "ford");
        l = (Literal) toSet(sc.getStatements(ford, RDFS.COMMENT, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("he really knows where his towel is", l.getLabel());
        assertNull(l.getDatatype());
        URI thor = vf.createURI(prefix + "thor");

        // Get an actual language-tagged literal from the triple store.
        URI foafName = vf.createURI("http://xmlns.com/foaf/0.1/name");
        Iterator<Statement> iter = toSet(sc.getStatements(thor, foafName, null, false)).iterator();
        boolean found = false;
        while (iter.hasNext()) {
            l = (Literal) iter.next().getObject();
            if (l.getLanguage().equals("en")) {
                found = true;
                assertEquals("Thor", l.getLabel());
                assertNull(l.getDatatype());
            }
            // if (l.getLanguage().equals("is")) {
            // found = true;
            // assertEquals("?�r", l.getLabel());
            // }
        }
        assertTrue(found);

        // Get an actual data-typed literal from the triple-store.
        URI msnChatID = vf.createURI("http://xmlns.com/foaf/0.1/msnChatID");
        l = (Literal) toSet(sc.getStatements(thor, msnChatID, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("Thorster123", l.getLabel());
        assertEquals(XMLSchema.STRING, l.getDatatype());

        // Test Literal.xxxValue() methods for Literals read from the triple
        // store
        URI valueUri, hasValueUri;
        hasValueUri = vf.createURI(prefix + "hasValue");
        valueUri = vf.createURI(prefix + "stringValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("foo", l.getLabel());
        assertEquals(XMLSchema.STRING, l.getDatatype());
        valueUri = vf.createURI(prefix + "byteValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("99", l.getLabel());
        assertEquals(XMLSchema.BYTE, l.getDatatype());
        assertEquals((byte) 'c', l.byteValue());
        valueUri = vf.createURI(prefix + "booleanValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("false", l.getLabel());
        assertEquals(XMLSchema.BOOLEAN, l.getDatatype());
        assertEquals(false, l.booleanValue());
        valueUri = vf.createURI(prefix + "intValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("42", l.getLabel());
        assertEquals(XMLSchema.INT, l.getDatatype());
        assertEquals(42, l.intValue());
        valueUri = vf.createURI(prefix + "shortValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("42", l.getLabel());
        assertEquals(XMLSchema.SHORT, l.getDatatype());
        assertEquals((short) 42, l.shortValue());
        valueUri = vf.createURI(prefix + "longValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("42", l.getLabel());
        assertEquals(XMLSchema.LONG, l.getDatatype());
        assertEquals(42l, l.longValue());
        valueUri = vf.createURI(prefix + "floatValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("3.1415926", l.getLabel());
        assertEquals(XMLSchema.FLOAT, l.getDatatype());
        assertEquals((float) 3.1415926, l.floatValue());
        valueUri = vf.createURI(prefix + "doubleValue");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("3.1415926", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());
        assertEquals(3.1415926, l.doubleValue());
        valueUri = vf.createURI(prefix + "dateTimeValue");
        calendar = XMLDatatypeUtil.parseCalendar("2002-10-10T12:00:00-05:00");
        l = (Literal) toSet(sc.getStatements(valueUri, hasValueUri, null, false)).iterator().next().getObject();
        assertNotNull(l);
        assertNull(l.getLanguage());
        assertEquals("2002-10-10T12:00:00-05:00", l.getLabel());
View Full Code Here

        URI uriA = sail.getValueFactory().createURI("http://example.org/test/S_POG#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/S_POG#b");
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            ValueFactory factory = sail.getValueFactory();
            BNode bNode = factory.createBNode();
            try {
                sc.addStatement(uriA, uriA, bNode);
            } catch (SailException se) {
                // FIXME: not supporting blank nodes ATM
                assertTrue(se.getCause() instanceof UnsupportedOperationException);
View Full Code Here

TOP

Related Classes of org.openrdf.model.ValueFactory

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.