Back to Top

Web API

Web API: Relation Extraction

AlchemyAPI provides easy-to-use facilities for performing Subject-Action-Object relation extraction on your publicly-accessible web-based content. These URL processing calls automatically fetch the desired Internet webpage, normalize / clean it (removing ads, navigation links, and other unimportant content), and extract Subject-Action-Object relations. These API calls may be utilized to process hosted webpages, blogs, and other publicly-accessible Internet content. If you are processing content that is not hosted on a public webserver, use our HTML API calls instead.

API Call: URLGetRelations

Description: The URLGetRelations call is utilized to extract Subject-Action-Object relations from a given web page. AlchemyAPI will download the requested URL, extracting text from the HTML document structure (ignoring navigation links, advertisements, and other undesireable content), and perform relation extraction operations.

Endpoint: http://access.alchemyapi.com/calls/url/URLGetRelations

Parameters:

http argument parameter description
url http url (must be uri-argument encoded)

(required parameter)
apikey your private api key

(required parameter)
maxRetrieve maximum number of relations to extract (default: 50, maximum: 100)

(optional parameter)
outputMode desired API output format

Possible values:
xml (default)
json
rdf

(optional parameter)
jsonp desired JSONP callback

(optional parameter, requires "outputMode" to be set to json)
sentiment whether to enable directional sentiment analysis.

Possible values:
1 - enabled
0 - disabled (default)

(optional parameter - Note that enabling this option will incur usage of one (1) additional AlchemyAPI transaction)
entities whether to enable relation subject/object entity extraction.

Possible values:
1 - enabled
0 - disabled (default)

(optional parameter - Note that enabling this option will incur usage of one (1) additional AlchemyAPI transaction)
requireEntities whether to only show extracted relations that contain at least one named entity, ignoring relations containing no entities.

Possible values:
1 - enabled
0 - disabled (default)

(optional parameter)
sentimentExcludeEntities whether to exclude relation subject/object named entity text from sentiment processing. (For example, not analyzing "New" in "New York")

Possible values:
1 - enabled (default)
0 - disabled

(optional parameter)
disambiguate whether to disambiguate detected relation subject/object named entities.

Possible values:
1 - enabled (default)
0 - disabled

(optional parameter)
linkedData whether to include Linked Data content links with identified relation subject/object named entities.

Possible values:
1 - enabled (default)
0 - disabled

(optional parameter.)
coreference whether to resolve he/she/etc coreferences in detected relation subject/object named entities.

Possible values:
1 - enabled (default)
0 - disabled

(optional parameter)
showSourceText whether to include the original 'source text' the relations were extracted from within the API response.

Possible values:
1 - enabled
0 - disabled (default)

(optional parameter)
sourceText where to obtain the text that will be processed by this API call.

AlchemyAPI supports multiple modes of text extraction: web page cleaning (removes ads, navigation links, etc.), raw text extraction (processes all web page text, including ads / nav links), visual constraint queries, and XPath queries.

Possible values:
cleaned_or_raw cleaning enabled, fallback to raw when cleaning produces no text (default)
cleaned operate on 'cleaned' web page text (web page cleaning enabled)
raw operate on raw web page text (web page cleaning disabled)
cquery operate on the results of a visual constraints query

Note: The 'cquery' http argument must also be set to a valid visual constraints query.
xpath operate on the results of an XPath query

Note: The 'xpath' http argument must also be set to a valid XPath query.

(optional parameter)
cquery a visual constraints query to apply to the web page.

Constraint queries enable API operations to be performed on a targeted area of a web page, such as a story title or product description.

(optional parameter, used when sourceText is set to 'cquery'. must be uri-argument encoded)
xpath an XPath query to apply to the web page.

XPath queries enable API operations to be performed on a targeted area of a web page, such as a story title or product description.

(optional parameter, used when sourceText is set to 'xpath'. must be uri-argument encoded)
baseUrl rel-tag output base http url (must be uri-argument encoded)

(optional parameter, used with rel-tag or rel-tag-raw outputMode.)

Response Format (XML):

<results>
    <status>REQUEST_STATUS</status>
    <url>REQUESTED_URL</url>
    <language>DOCUMENT_LANGUAGE</language>
    <text>DOCUMENT_TEXT</text>
    <relations>
        <relation>
            <subject>
                <text>DETECTED_SUBJECT</text>
                <sentiment>
                    <type>SUBJECT_SENTIMENT_POLARITY</type>
                    <score>SUBJECT_SENTIMENT_SCORE</score>
                    <mixed>SUBJECT_SENTIMENT_MIXED</mixed>
                </sentiment>
                <entity>
                    <type>OBJECT_ENTITY_TYPE</type>
                    <text>OBJECT_ENTITY_TEXT</text>
                    <disambiguated>
                        <name>DISAMBIGUATED_ENTITY</name>
                        <subType>ENTITY_SUBTYPE</subType>
                        <website>WEBSITE</website>
                        <geo>LATITUDE LONGITUDE</geo>
                        <dbpedia>LINKED_DATA_DBPEDIA</dbpedia>
                        <yago>LINKED_DATA_YAGO</yago>
                        <opencyc>LINKED_DATA_OPENCYC</opencyc>
                        <umbel>LINKED_DATA_UMBEL</umbel>
                        <freebase>LINKED_DATA_FREEBASE</freebase>
                        <ciaFactbook>LINKED_DATA_FACTBOOK</ciaFactbook>
                        <census>LINKED_DATA_CENSUS</census>
                        <geonames>LINKED_DATA_GEONAMES</geonames>
                        <musicBrainz>LINKED_DATA_MUSICBRAINZ</musicBrainz>
                        <crunchbase>CRUNCHBASE_WEB_LINK</crunchbase>
                        <semanticCrunchbase>LINKED_DATA_CRUNCHBASE</semanticCrunchbase>
                    </disambiguated>
                </entity>
            </subject>
            <action>
                <text>DETECTED_ACTION</text>
                <lemmatized>LEMMATIZED_ACTION</lemmatized>
                <verb>
                    <text>VERB_TEXT</text>
                    <tense>VERB_TENSE</tense>
                    <negated>VERB_IS_NEGATED</negated>
                </verb>
            </action>
            <object>
                <text>DETECTED_OBJECT</text>
                <sentiment>
                    <type>OBJECT_SENTIMENT_POLARITY</type>
                    <score>OBJECT_SENTIMENT_SCORE</score>
                    <mixed>OBJECT_SENTIMENT_MIXED</mixed>
                </sentiment>
                <sentimentFromSubject>
                    <type>OBJ_FROM_SBJ_SENTIMENT_POLARITY</type>
                    <score>OBJ_FROM_SBJ_SENTIMENT_SCORE</score>
                    <mixed>OBJ_FROM_SBJ_SENTIMENT_MIXED</mixed>
                </sentimentFromSubject>
                <entity>
                    <type>OBJECT_ENTITY_TYPE</type>
                    <text>OBJECT_ENTITY_TEXT</text>
                    <disambiguated>
                        <name>DISAMBIGUATED_ENTITY</name>
                        <subType>ENTITY_SUBTYPE</subType>
                        <website>WEBSITE</website>
                        <geo>LATITUDE LONGITUDE</geo>
                        <dbpedia>LINKED_DATA_DBPEDIA</dbpedia>
                        <yago>LINKED_DATA_YAGO</yago>
                        <opencyc>LINKED_DATA_OPENCYC</opencyc>
                        <umbel>LINKED_DATA_UMBEL</umbel>
                        <freebase>LINKED_DATA_FREEBASE</freebase>
                        <ciaFactbook>LINKED_DATA_FACTBOOK</ciaFactbook>
                        <census>LINKED_DATA_CENSUS</census>
                        <geonames>LINKED_DATA_GEONAMES</geonames>
                        <musicBrainz>LINKED_DATA_MUSICBRAINZ</musicBrainz>
                        <crunchbase>CRUNCHBASE_WEB_LINK</crunchbase>
                        <semanticCrunchbase>LINKED_DATA_CRUNCHBASE</semanticCrunchbase>
                    </disambiguated>
                </entity>
            </object>
        </relation>
    </relations>
</results>

Response Format (JSON):

{
    "status": "REQUEST_STATUS",
    "url": "REQUESTED_URL",
    "language": "DOCUMENT_LANGUAGE",
    "text": "DOCUMENT_TEXT",/text>
    "relations": [
        {
            "subject": {
                "text": "DETECTED_SUBJECT",
                "sentiment": {
                    "type": "SUBJECT_SENTIMENT_POLARITY",
                    "score": "SUBJECT_SENTIMENT_SCORE",
                    "mixed": "SUBJECT_SENTIMENT_MIXED"
                },
                "entity": {
                    "type": "SUBJECT_ENTITY_TYPE",
                    "text": "SUBJECT_ENTITY_TEXT"
                    "disambiguated": {
                        "name": "DISAMBIGUATED_ENTITY",
                        "subType": "ENTITY_SUBTYPE",
                        "website": "WEBSITE",
                        "geo": "LATITUDE LONGITUDE",
                        "dbpedia": "LINKED_DATA_DBPEDIA",
                        "yago": "LINKED_DATA_YAGO",
                        "opencyc": "LINKED_DATA_OPENCYC",
                        "umbel": "LINKED_DATA_UMBEL",
                        "freebase": "LINKED_DATA_FREEBASE",
                        "ciaFactbook": "LINKED_DATA_FACTBOOK",
                        "census": "LINKED_DATA_CENSUS",
                        "geonames": "LINKED_DATA_GEONAMES",
                        "musicBrainz": "LINKED_DATA_MUSICBRAINZ",
                        "crunchbase": "CRUNCHBASE_WEB_LINK",
                        "semanticCrunchbase": "LINKED_DATA_CRUNCHBASE"
                    }
                }
            },
            "action": {
                "text": "DETECTED_ACTION",
                "lemmatized": "LEMMATIZED_ACTION",
                "verb": {
                    "text": "VERB_TEXT",
                    "tense": "VERB_TENSE",
                    "negated": "VERB_IS_NEGATED"
                }
            },
            "object": {
                "text": "DETECTED_OBJECT",
                "sentiment": {
                    "type": "OBJECT_SENTIMENT_POLARITY",
                    "score": "OBJECT_SENTIMENT_SCORE",
                    "mixed": "OBJECT_SENTIMENT_MIXED"
                },
                "sentimentFromSubject": {
                    "type": "OBJ_FROM_SBJ_SENTIMENT_POLARITY",
                    "score": "OBJ_FROM_SBJ_SENTIMENT_SCORE",
                    "mixed": "OBJ_FROM_SBJ_SENTIMENT_MIXED"
                },
                "entity": {
                    "type": "OBJECT_ENTITY_TYPE",
                    "text": "OBJECT_ENTITY_TEXT"
                    "disambiguated": {
                        "name": "DISAMBIGUATED_ENTITY",
                        "subType": "ENTITY_SUBTYPE",
                        "website": "WEBSITE",
                        "geo": "LATITUDE LONGITUDE",
                        "dbpedia": "LINKED_DATA_DBPEDIA",
                        "yago": "LINKED_DATA_YAGO",
                        "opencyc": "LINKED_DATA_OPENCYC",
                        "umbel": "LINKED_DATA_UMBEL",
                        "freebase": "LINKED_DATA_FREEBASE",
                        "ciaFactbook": "LINKED_DATA_FACTBOOK",
                        "census": "LINKED_DATA_CENSUS",
                        "geonames": "LINKED_DATA_GEONAMES",
                        "musicBrainz": "LINKED_DATA_MUSICBRAINZ",
                        "crunchbase": "CRUNCHBASE_WEB_LINK",
                        "semanticCrunchbase": "LINKED_DATA_CRUNCHBASE"
                    }
                }
            }
        }
    ]
}

Response Format (RDF):

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                 xmlns:aapi="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#"
                 xml:base="http://rdf.alchemyapi.com/rdf/v1/r/response.rdf">
    <rdf:Description rdf:ID="DOCUMENT_HASH">
        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#DocInfo"/>
        <aapi:ResultStatus>REQUEST_STATUS</aapi:ResultStatus>
        <aapi:URL>DOCUMENT_URL</aapi:URL>
        <aapi:Language>DOCUMENT_LANGUAGE</aapi:Language>
        <aapi:DocText>DOCUMENT_TEXT</aapi:DocText>
    </rdf:Description>
    <rdf:Description rdf:ID="DOCUMENT_HASH-r_RELATION_NUM">
        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#RelationOccurrence"/>
        <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
        <aapi:RelationSubject>
            <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#RelationSubject"/>
                <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                <aapi:Text>DETECTED_SUBJECT</aapi:Text>
                <aapi:SubjectSentiment>
                    <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#SubjectSentiment"/>
                        <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                        <aapi:SentimentType>SUBJECT_SENTIMENT_POLARITY</aapi:SentimentType>
                        <aapi:SentimentScore>SUBJECT_SENTIMENT_SCORE</aapi:SentimentScore>
                        <aapi:SentimentMixed>SUBJECT_SENTIMENT_MIXED</aapi:SentimentMixed>
                    </rdf:Description>
                </aapi:SubjectSentiment>
                <aapi:SubjectEntity>
                    <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#SubjectEntity"/>
                        <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                        <aapi:Disambiguation>
                            <rdf:Description rdf:about="#DOCUMENT_HASH-r_RELATION_NUM">
                                <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#Disambiguation"/>
                                <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                                <aapi:ResolvedName>DISAMBIGUATED_ENTITY</aapi:ResolvedName>
                                <aapi:SubType>ENTITY_SUBTYPE</aapi:SubType>
                                <aapi:URL>WEBSITE</aapi:URL>
                                <aapi:Geo>LATITUDE LONGITUDE</aapi:Geo>
                                <owl:sameAs rdf:resource="LINKED_DATA_DBPEDIA"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_YAGO"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_OPENCYC"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_UMBEL"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_FREEBASE"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_FACTBOOK"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_CENSUS"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_GEONAMES"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_MUSICBRAINZ"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_CRUNCHBASE"/>
                            </rdf:Description>
                        </aapi:Disambiguation>
                    </rdf:Description>
                </aapi:SujectEntity>
            </rdf:Description>
        </aapi:RelationSubject>
        <aapi:RelationAction>
            <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#RelationAction"/>
                <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                <aapi:Text>DETECTED_ACTION</aapi:Text>
                <aapi:LemmatizedText>LEMMATIZED_ACTION</aapi:LemmatizedText>
                <aapi:VerbText>VERB_TEXT</aapi:VerbText>
                <aapi:VerbTense>VERB_TENSE</aapi:VerbTense>
                <aapi:VerbNegated>VERB_IS_NEGATED</aapi:VerbNegated>
            </rdf:Description>
        </aapi:RelationAction>
        <aapi:RelationObject>
            <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#RelationObject"/>
                <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                <aapi:Text>DETECTED_OBJECT</aapi:Text>
                <aapi:ObjectSentiment>
                    <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#ObjectSentiment"/>
                        <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                        <aapi:SentimentType>OBJECT_SENTIMENT_POLARITY</aapi:SentimentType>
                        <aapi:SentimentScore>OBJECT_SENTIMENT_SCORE</aapi:SentimentScore>
                        <aapi:SentimentMixed>OBJECT_SENTIMENT_MIXED</aapi:SentimentMixed>
                    </rdf:Description>
                </aapi:ObjectSentiment>
                <aapi:ObjectSentimentFromSubject>
                    <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#ObjectSentiment"/>
                        <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                        <aapi:SentimentType>OBJ_FROM_SBJ_SENTIMENT_POLARITY</aapi:SentimentType>
                        <aapi:SentimentScore>OBJ_FROM_SBJ_SENTIMENT_SCORE</aapi:SentimentScore>
                        <aapi:SentimentMixed>OBJ_FROM_SBJ_SENTIMENT_MIXED</aapi:SentimentMixed>
                    </rdf:Description>
                </aapi:ObjectSentimentFromSubject>
                <aapi:ObjectEntity>
                    <rdf:Description rdf:about="DOCUMENT_HASH-r_RELATION_NUM">
                        <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#ObjectEntity"/>
                        <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                        <aapi:Disambiguation>
                            <rdf:Description rdf:about="#DOCUMENT_HASH-r_RELATION_NUM">
                                <rdf:type rdf:resource="http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#Disambiguation"/>
                                <aapi:Doc>DOCUMENT_HASH</aapi:Doc>
                                <aapi:ResolvedName>DISAMBIGUATED_ENTITY</aapi:ResolvedName>
                                <aapi:SubType>ENTITY_SUBTYPE</aapi:SubType>
                                <aapi:URL>WEBSITE</aapi:URL>
                                <aapi:Geo>LATITUDE LONGITUDE</aapi:Geo>
                                <owl:sameAs rdf:resource="LINKED_DATA_DBPEDIA"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_YAGO"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_OPENCYC"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_UMBEL"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_FREEBASE"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_FACTBOOK"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_CENSUS"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_GEONAMES"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_MUSICBRAINZ"/>
                                <owl:sameAs rdf:resource="LINKED_DATA_CRUNCHBASE"/>
                            </rdf:Description>
                        </aapi:Disambiguation>
                    </rdf:Description>
                </aapi:ObjectEntity>
            </rdf:Description>
        </aapi:RelationObject>
    </rdf:Description>
</rdf:RDF>

Response Fields:

field name field description
status success / failure status indicating whether the request was processed.

Possible values:
OK
ERROR
language the detected language that the source text was written in.
url http url information was requested for.
text the detected subject, action, and object text
lemmatized lemmatized text of the detected relation action
sentiment sentiment data for the detected subject and object (sent only if sentiment analysis is enabled)
sentiment field field description
type the sentiment polarity associated with the subject or object
score the sentiment score (0.0 - 1.0) associated with the subject or object
mixed whether sentiment is mixed (both positive and negative) (1 == mixed)
sentimentFromSubject sentiment data targeted towards the detected object, from the detected subject, via the detected action (sent only if sentiment analysis is enabled)
sentiment field field description
type the sentiment polarity directed towards the object
score the sentiment score (0.0 - 1.0) directed towards the object
mixed whether sentiment is mixed (both positive and negative) (1 == mixed)
verb verb data for the detected action
field field description
text lemmatized base form of the detected action verb
tense tense of the detected action verb: past, present, future
negated whether this action verb was negated in the detected relation: 1 = negated, 0 = not negated
entity named entity data for the detected subject and object (sent only if entity extraction is enabled)
entity field field description
type the named entity type associated with the subject or object
text the named entity text associated with the subject or object
disambiguated disambiguation information for the detected subject/object entity (sent only if disambiguateoccurred)
disambiguation field field description
name the disambiguated entity name.
subType the disambiguated entity subType

SubTypes expose additional ontological mappings for a detected entity, such as identification of a Person as a Politician or Athlete.
website the website associated with this named entity.
geo latitude longitude

the geographic coordinates associated with this named entity.
dbpedia sameAs link to DBpedia for this named entity.

Note: Provided only for entities that exist in this linked data-set.
yago sameAs link to YAGO for this named entity.

Note: Provided only for entities that exist in this linked data-set.
opencyc sameAs link to OpenCyc for this named entity.

Note: Provided only for entities that exist in this linked data-set.
freebase sameAs link to Freebase for this named entity.

Note: Provided only for entities that exist in this linked data-set.
ciaFactbook sameAs link to the CIA World Factbook for this named entity.

Note: Provided only for entities that exist in this linked data-set.
census sameAs link to the US Census for this named entity.

Note: Provided only for entities that exist in this linked data-set.
geonames sameAs link to Geonames for this named entity.

Note: Provided only for entities that exist in this linked data-set.
musicBrainz sameAs link to MusicBrainz for this named entity.

Note: Provided only for entities that exist in this linked data-set.
crunchbase website link to CrunchBase for this named entity.

Note: Provided only for entities that exist in CrunchBase.
semanticCrunchbase sameAs link to Semantic CrunchBase for this named entity.

Note: Provided only for entities that exist in this linked data-set.
statusInfo failure status information (sent only if "status" == "ERROR").

Possible values:
invalid-api-key
cannot-retrieve
page-is-not-html

Example Call:

XML: http://access.alchemyapi.com/calls/...
RDF: http://access.alchemyapi.com/calls/...

API Notes:

  1. Calls to URLGetRelations can be made using HTTP GET or POST.
  2. HTTP POST calls should include the Content-Type header: application/x-www-form-urlencoded
  3. URL retrieval is attempted for a maximum of 10 seconds. Requests taking longer than this will result in a "cannot-retrieve" error response.
  4. Requested HTML documents can be a maximum of 600 kilobytes. Larger documents will result in a "content-exceeds-size-limit" error response.
  5. Language detection is performed on the retrieved document before attempting relation extraction. A minimum of 15 characters of text must exist within the requested HTTP document to perform language detection.
  6. Documents containing less than 15 characters of text are assumed to be English-language content.
  7. Relation is currently supported for English-language content. Other non-supported language submissions will be rejected and an error response returned.
  8. Enabling directional sentiment analysis results in one additional transaction utilized against your daily API limit.
  9. Enabling subject/object entity extraction results in one additional transaction utilized against your daily API limit.