Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Data Fusion /
avatar image
REFINITIV
Question by Tomasz Adamusiak · Sep 06, 2017 at 11:57 AM · Datafusiontransformation

How can I set up a transformation that creates a new field based on a literal value of another field and a lookup map?

My original data source contains ISO country codes that I would like to expand into full country names and add as an additional property to my original data source to facilitate concordance to Organization Authority.

Example data:

CTRYISOCD

CHN

CHN

JPN

SGP

ARG

DEU

BRA

MEX

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Reply

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Tomasz Adamusiak · Sep 06, 2017 at 02:12 PM

The following SPARQL and transformation scripts would work in this case.

SPARQL query

SELECT * FROM NAMED <http://rdf.entagen.com/context/context_name> WHERE 
{
	GRAPH ?g {		?s <http://rdf.entagen.com/context/context_name/property/ISOCD> ?o .
	}
}

Transformation code

import org.openrdf.model.*
import org.openrdf.model.impl.*
import com.entagen.masterindex.api.*
import com.entagen.masterindex.search.*

/** Generates new RDF based on the Sparql query results.
*
*/

public Collection<Statement> transformAsRdf(Map<String, Value> values) {
        def countryMap = [
        ABW:"Aruba",AFG:"Afghanistan",AGO:"Angola",AIA:"Anguilla",ALA:"Åland Islands",ALB:"Albania",AND:"Andorra",ARE:"United Arab Emirates",ARG:"Argentina",ARM:"Armenia",ASM:"American Samoa",ATA:"Antarctica"
        ]
    
	def subject = values.s
        def predicate = new URIImpl("http://rdf.entagen.com/context/property/country_name")
        def object = new LiteralImpl(countryMap[values.o.stringValue()].toUpperCase()) ?: new LiteralImpl("UNKNOWN")
        def context = values.g 

        return [new ContextStatementImpl(subject, predicate, object, context)]

}

/** Generates new Annotations based on the Sparql query results.
*
*/

public Collection<AnnotationDto> transformAsAnnotations(Map<String, Value> values) {
    return null
}

Explanation

Values.o is an implementation of org.openrdf.model.Value

It won’t work directly as a key lookup in the countryMap. We need to retrieve its string value by calling the values.o.stringValue() method first.

Finally, we need to push it back into a Literal, so wrapping it in a new LiteralImpl().

Comment
heather.benoit

People who like this

1 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
7 People are following this question.

Related Questions

Data Fustion API /entity/analize/connect response

/entity/search scores

Filter entities by relationship type

Deleting Data From DF

Score parameter and prioritization in Data Fusion API

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges