PHPackages                             morria/code2seq-paths-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. morria/code2seq-paths-php

ActiveProject[Utility &amp; Helpers](/categories/utility)

morria/code2seq-paths-php
=========================

Produce function paths suitable for use by code2seq

0.5(3y ago)010MITPHPPHP &gt;7.4

Since Mar 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/morria/code2seq-paths-php)[ Packagist](https://packagist.org/packages/morria/code2seq-paths-php)[ RSS](/packages/morria-code2seq-paths-php/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (6)Used By (0)

PHP Code2Seq Paths
==================

[](#php-code2seq-paths)

Read PHP source code and produce a file suitable for use by [code2seq](http://code2seq.org)for training and evaluating a model.

Usage
-----

[](#usage)

To build the package just run `composer install`. Make sure you have PHP installed along with the [php-ast](https://github.com/nikic/php-ast) extension. You can also use the Docker container with all dependencies defined in `.devcontainer`.

Once built you can run the tool via

```
./bin/code2seq-paths path/to/php/dir > method_contexts.c2s

```

and from here you can use the file `method_contexts.c2s` as input to [code2seq](https://github.com/tech-srl/code2seq). Keep in mind that the file produced here will need to be preprocessed within `code2seq`.

**TODO**: describe how to do that.

Flags
-----

[](#flags)

You can see the available flags via `./bin/code2seq-paths --help`.

```
Usage: ./bin/code2seq-paths [options] [files...]]
 -h, --help
 Get this help information

 -s SEED, --seed SEED
 The seed to use before shuffling the target contexts.

 -l LENGTH, --max-length=LENGTH
 The maximum length of a target context. Defaults to unbounded.

 -i, --ids
 Use IDs rather than names for context nodes. Defaults to false.

 ...
 All other options will be treated as file names to
 read as PHP source.

```

Docker
------

[](#docker)

To avoid setting up a proper environment, you can run `code2seq-paths-php` from a Docker image as follows.

```
docker pull morria/code2seq-paths-php
docker run --name code2seq-paths-php --volume PATH_TO_SOURCE:/workspace morria/code2seq-paths-php /workspace/

```

To build the container from source run the following.

```
composer install
docker build -t morria/code2seq-paths-php .

```

Output Format
-------------

[](#output-format)

The output is structured as follows.

```
LINE := FUNCTION_NAME WS CONTEXT_LIST;

FUNCTION_NAME := string;

WS := ' ';

CONTEXT_LIST := SOURCE_TERMINAL ',' NODE_LIST ',' TARGET_TERMINAL;

SOURCE_TERMINAL := TOKEN_LIST;
TARGET_TERMINAL := TOKEN_LIST;

NODE_LIST := NODE
          | NODE '|' NODE_LIST
          ;

NODE := string;

```

For the input code

```
