FOAF#

FOAF Module#

This module provides Python classes representing FOAF (Friend of a Friend) entities. These classes allow modeling agents, people, groups, and organizations with their commonly used FOAF properties in an RDF graph or other semantic applications.

Classes#

  • FOAFAgent The most general FOAF entity. Can represent any actor such as a person, group, or organization. Supports properties such as foaf:name, foaf:homepage, foaf:knows, foaf:depiction, etc.

  • FOAFPerson Represents an individual human being. Inherits from Agent. Supports properties like foaf:firstName, foaf:lastName, foaf:nick, foaf:img, foaf:knows, etc.

  • FOAFGroup Represents a collection of people, such as a team, club, or association. Inherits from Agent. Supports properties such as foaf:member, foaf:homepage, foaf:logo, etc.

  • FOAFOrganization Represents an organization such as a company, institution, or agency. Inherits from Agent. Supports properties like foaf:member, foaf:homepage, foaf:logo, foaf:fundedBy, etc.

Usage#

You can import the classes and create instances representing FOAF entities:

import fdp

# create a foaf:Person entity
alice = fdp.foaf.FOAFPerson()

# add details to the Person
alice.name = 'Alice'
alice.homepage = 'https://www.example.com/alice'

# create a foaf:Group entity
team = fdp.foaf.FOAFGroup()

# add details to the Group
team.name = 'A Team'
team.homepage = 'https://www.example.com/a-team'

# add Alice to the group
team.add_member(alice)

# create a Sofia foaf:Person and add to the group
team.add_member(
    fdp.foaf.FOAFPerson(name='Sofia',
                        homepage='https://www.example.com/sofia'))

# inspect the Group
import pprint
pprint.pprint(team.inspect())

# retrieve the Group's rdf graph
team_graph = team.rdf

# pretty print the Group's rdf graph
print(team_graph.serialize())

# create a team with details
new_team = fdp.foaf.FOAFGroup(
    name='B-Team',
    homepage='https://www.example.com/b-team',
    member=[
        fdp.foaf.FOAFPerson(
            name='Mario',
            homepage='https://www.example.com/mario'),
        fdp.foaf.FOAFPerson(
            name='Marco',
            homepage='https://www.example.com/marco')
    ])
class fdp.foaf.FOAFAgent(fair_data_point: FairDataPoint = None, iri: str = None, uuid: str = None, *args, **kwargs)#

Bases: FairDataPointItem

A class representing a FOAF Agent.

The most general FOAF entity: represents anything that can act (e.g., a person, group, or organization). All other FOAF entities inherit from Agent.

Supported FOAF properties:
  • name

  • homepage

  • members

property homepage#

The foaf:homepage property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string containing the URL (e.g., "https://example.org")

  • an rdflib.term.Literal representing a URL

  • an rdflib.term.URIRef instance

  • an rdflib.graph.Graph containing one or more foaf:homepage triples

Warning

If a graph is provided either as the value or via the namespace, and it contains multiple foaf:homepage triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.term.URIRef

Return type:

str

Returns:

The homepage URL of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid URL.

property name#

The foaf:name property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string (e.g., "Alice Smith")

  • an rdflib.term.Literal representing a name

  • an rdflib.graph.Graph containing one or more foaf:name triples

Warning

If a graph contains multiple foaf:name triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.graph.Graph

Return type:

str

Returns:

The name of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid name.

property member: dict#

The foaf:member property.

The setter for this property is the function add_member.

add_member(member: FOAFAgent | Graph | list[FOAFAgent]) None#

Add one or more members.

This function accepts either a single FOAFAgent instance (or any of its subclasses), an rdflib.graph.Graph object containing agent data, or a list of FOAFAgent instances (or subclasses). The provided member(s) are added to the instance RDF graph, creating the corresponding RDF triples as needed.

Parameters:

member (FOAFAgent | rdflib.Graph | list[FOAFAgent]) –

The member or members to add. It can be one of the following:

  • An FOAFAgent instance or subclass

  • An rdflib.graph.Graph instance

  • A list of FOAFAgent instances or subclasses

Returns:

None

Return type:

None

Raises:

TypeError – If the input type is not supported.

Note

  • When a list is provided, each element must be an instance of

    FOAFAgent or one of its subclasses.

  • When a rdflib.graph.Graph is provided and it contains

    more than one member description, all members found in the graph are added.

class fdp.foaf.FOAFPerson(fair_data_point: FairDataPoint = None, iri: str = None, uuid: str = None, *args, **kwargs)#

Bases: FOAFAgent

A class representing a FOAF Person.

Represents an individual human being. Inherits from Agent.

Supported FOAF properties:
  • name

  • homepage

property homepage#

The foaf:homepage property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string containing the URL (e.g., "https://example.org")

  • an rdflib.term.Literal representing a URL

  • an rdflib.term.URIRef instance

  • an rdflib.graph.Graph containing one or more foaf:homepage triples

Warning

If a graph is provided either as the value or via the namespace, and it contains multiple foaf:homepage triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.term.URIRef

Return type:

str

Returns:

The homepage URL of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid URL.

property name#

The foaf:name property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string (e.g., "Alice Smith")

  • an rdflib.term.Literal representing a name

  • an rdflib.graph.Graph containing one or more foaf:name triples

Warning

If a graph contains multiple foaf:name triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.graph.Graph

Return type:

str

Returns:

The name of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid name.

class fdp.foaf.FOAFGroup(fair_data_point: FairDataPoint = None, iri: str = None, uuid: str = None, *args, **kwargs)#

Bases: FOAFAgent

A class representing a FOAF Group.

Represents a collection of people, e.g., a team or club. Inherits from Agent.

Supported FOAF properties:
  • name

  • member

  • homepage

add_member(member: FOAFAgent | Graph | list[FOAFAgent]) None#

Add one or more members.

This function accepts either a single FOAFAgent instance (or any of its subclasses), an rdflib.graph.Graph object containing agent data, or a list of FOAFAgent instances (or subclasses). The provided member(s) are added to the instance RDF graph, creating the corresponding RDF triples as needed.

Parameters:

member (FOAFAgent | rdflib.Graph | list[FOAFAgent]) –

The member or members to add. It can be one of the following:

  • An FOAFAgent instance or subclass

  • An rdflib.graph.Graph instance

  • A list of FOAFAgent instances or subclasses

Returns:

None

Return type:

None

Raises:

TypeError – If the input type is not supported.

Note

  • When a list is provided, each element must be an instance of

    FOAFAgent or one of its subclasses.

  • When a rdflib.graph.Graph is provided and it contains

    more than one member description, all members found in the graph are added.

property homepage#

The foaf:homepage property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string containing the URL (e.g., "https://example.org")

  • an rdflib.term.Literal representing a URL

  • an rdflib.term.URIRef instance

  • an rdflib.graph.Graph containing one or more foaf:homepage triples

Warning

If a graph is provided either as the value or via the namespace, and it contains multiple foaf:homepage triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.term.URIRef

Return type:

str

Returns:

The homepage URL of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid URL.

property member: dict#

The foaf:member property.

The setter for this property is the function add_member.

property name#

The foaf:name property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string (e.g., "Alice Smith")

  • an rdflib.term.Literal representing a name

  • an rdflib.graph.Graph containing one or more foaf:name triples

Warning

If a graph contains multiple foaf:name triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.graph.Graph

Return type:

str

Returns:

The name of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid name.

class fdp.foaf.FOAFOrganization(fair_data_point: FairDataPoint = None, iri: str = None, uuid: str = None, *args, **kwargs)#

Bases: FOAFAgent

A class representing a FOAF Organization.

Represents an organization such as a company, institution, or agency. Inherits from Agent.

Supported FOAF properties:
  • name

  • member

  • homepage

add_member(member: FOAFAgent | Graph | list[FOAFAgent]) None#

Add one or more members.

This function accepts either a single FOAFAgent instance (or any of its subclasses), an rdflib.graph.Graph object containing agent data, or a list of FOAFAgent instances (or subclasses). The provided member(s) are added to the instance RDF graph, creating the corresponding RDF triples as needed.

Parameters:

member (FOAFAgent | rdflib.Graph | list[FOAFAgent]) –

The member or members to add. It can be one of the following:

  • An FOAFAgent instance or subclass

  • An rdflib.graph.Graph instance

  • A list of FOAFAgent instances or subclasses

Returns:

None

Return type:

None

Raises:

TypeError – If the input type is not supported.

Note

  • When a list is provided, each element must be an instance of

    FOAFAgent or one of its subclasses.

  • When a rdflib.graph.Graph is provided and it contains

    more than one member description, all members found in the graph are added.

property homepage#

The foaf:homepage property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string containing the URL (e.g., "https://example.org")

  • an rdflib.term.Literal representing a URL

  • an rdflib.term.URIRef instance

  • an rdflib.graph.Graph containing one or more foaf:homepage triples

Warning

If a graph is provided either as the value or via the namespace, and it contains multiple foaf:homepage triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.term.URIRef

Return type:

str

Returns:

The homepage URL of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid URL.

property member: dict#

The foaf:member property.

The setter for this property is the function add_member.

property name#

The foaf:name property.

The property can be read or updated. When setting the value, several input types are accepted:

  • a plain string (e.g., "Alice Smith")

  • an rdflib.term.Literal representing a name

  • an rdflib.graph.Graph containing one or more foaf:name triples

Warning

If a graph contains multiple foaf:name triples, only the first one encountered is used.

Type:

str | rdflib.term.Literal | rdflib.graph.Graph

Return type:

str

Returns:

The name of the entity as a string.

Raises:

ValueError – If the value cannot be converted to a valid name.