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#
FOAFAgentThe 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.FOAFPersonRepresents an individual human being. Inherits fromAgent. Supports properties like foaf:firstName, foaf:lastName, foaf:nick, foaf:img, foaf:knows, etc.FOAFGroupRepresents a collection of people, such as a team, club, or association. Inherits fromAgent. Supports properties such as foaf:member, foaf:homepage, foaf:logo, etc.FOAFOrganizationRepresents an organization such as a company, institution, or agency. Inherits fromAgent. 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:
FairDataPointItemA 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:homepageproperty.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.Literalrepresenting a URLan
rdflib.term.URIRefinstancean
rdflib.graph.Graphcontaining one or morefoaf:homepagetriples
Warning
If a graph is provided either as the value or via the namespace, and it contains multiple
foaf:homepagetriples, 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:nameproperty.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.Literalrepresenting a namean
rdflib.graph.Graphcontaining one or morefoaf:nametriples
Warning
If a graph contains multiple
foaf:nametriples, 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:memberproperty.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
FOAFAgentinstance (or any of its subclasses), anrdflib.graph.Graphobject containing agent data, or a list ofFOAFAgentinstances (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:
- 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
FOAFAgentor one of its subclasses.
- When a
rdflib.graph.Graphis provided and it contains more than one member description, all members found in the graph are added.
- When a
- class fdp.foaf.FOAFPerson(fair_data_point: FairDataPoint = None, iri: str = None, uuid: str = None, *args, **kwargs)#
Bases:
FOAFAgentA class representing a FOAF Person.
Represents an individual human being. Inherits from
Agent.- Supported FOAF properties:
name
homepage
- property homepage#
The
foaf:homepageproperty.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.Literalrepresenting a URLan
rdflib.term.URIRefinstancean
rdflib.graph.Graphcontaining one or morefoaf:homepagetriples
Warning
If a graph is provided either as the value or via the namespace, and it contains multiple
foaf:homepagetriples, 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:nameproperty.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.Literalrepresenting a namean
rdflib.graph.Graphcontaining one or morefoaf:nametriples
Warning
If a graph contains multiple
foaf:nametriples, 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:
FOAFAgentA 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
FOAFAgentinstance (or any of its subclasses), anrdflib.graph.Graphobject containing agent data, or a list ofFOAFAgentinstances (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:
- 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
FOAFAgentor one of its subclasses.
- When a
rdflib.graph.Graphis provided and it contains more than one member description, all members found in the graph are added.
- When a
- property homepage#
The
foaf:homepageproperty.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.Literalrepresenting a URLan
rdflib.term.URIRefinstancean
rdflib.graph.Graphcontaining one or morefoaf:homepagetriples
Warning
If a graph is provided either as the value or via the namespace, and it contains multiple
foaf:homepagetriples, 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:memberproperty.The setter for this property is the function
add_member.
- property name#
The
foaf:nameproperty.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.Literalrepresenting a namean
rdflib.graph.Graphcontaining one or morefoaf:nametriples
Warning
If a graph contains multiple
foaf:nametriples, 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:
FOAFAgentA 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
FOAFAgentinstance (or any of its subclasses), anrdflib.graph.Graphobject containing agent data, or a list ofFOAFAgentinstances (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:
- 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
FOAFAgentor one of its subclasses.
- When a
rdflib.graph.Graphis provided and it contains more than one member description, all members found in the graph are added.
- When a
- property homepage#
The
foaf:homepageproperty.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.Literalrepresenting a URLan
rdflib.term.URIRefinstancean
rdflib.graph.Graphcontaining one or morefoaf:homepagetriples
Warning
If a graph is provided either as the value or via the namespace, and it contains multiple
foaf:homepagetriples, 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:memberproperty.The setter for this property is the function
add_member.
- property name#
The
foaf:nameproperty.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.Literalrepresenting a namean
rdflib.graph.Graphcontaining one or morefoaf:nametriples
Warning
If a graph contains multiple
foaf:nametriples, 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.