GitXplorerGitXplorer
k

fuzzy_interfaces

public
1 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
474780ba002c470eda635ae9bc74dde1f296692c

readme

kkmod committed 2 years ago
Unverified
892ad286c7a3b9b9359b2a8bf3d21665cb403b84

fuzzy interfaces

kkmod committed 2 years ago
Unverified
4e164ad94695cb4600ebe50f0f6d88e050a2649c

ok it works

kkmod committed 2 years ago
Unverified
aa031bf531321fa1e2631581df9d2363d79460f9

maybe spacy is too limited to english words

kkmod committed 2 years ago
Unverified
ca6a19cf3b4b85aa4b3d2b1b2d2c0797b7459b17

poc: fuzzy args

kkmod committed 2 years ago
Unverified
575326b97efbfeb9c3207af146922d2971a4e349

initial commit

kkmod committed 2 years ago

README

The README file for this repository.

fuzzy_interfaces

This is a proof of concept example of how we might include AI into a programming language. It is meant to be thought-provoking, not actually used.

fuzzy keywords

The most basic feature offered is for fuzzy keyword matching in function calls. It's easiest shown with an example:

from fuzzy_interfaces import fuzzy_keywords

@fuzzy_keywords
def myFunction(data):
    print("Was passed %r" % data)

# This works like normal:
myFunction(data="hello world")
# This works also works:
myFunction(content="foo bar")

This works by computing similarity scores for the passed keywords versus the accepted keywords.

The currently-implemented algorithm is very naive, and will over-match.

This is a bit contrived, but makes a bit more sense in the following example.

fuzzy modules

This same kind of idea can be used to implement fuzzy attribute lookup. In the case of modules, we can do the fuzzy attribute lookup and wrap any functions in a fuzzy keywords object.

from fuzzy_interfaces import FuzzyModule

fuzzy_requests = FuzzyModule("requests")

fuzzy_requests.fetch(link="http://example.com")
# The actual API is requests.get(url)

While I wouldn't necessarily recommend doing this, it dramatically changes how we consume unknown APIs: instead of looking up documentation (or using something like Copilot that has memorized the documentation), we simply write out something semantically correct, and let the system map it to the actual arguments.

fuzzy interfaces

The most interesting usage, in my opinion, is creating fuzzy interfaces. We can imagine the previous use cases being resolved statically and written out without any fuzziness. But with fuzzy interfaces we can actually support use cases that are not possible without fuzziness.

In particular, we can write a function that accepts objects of similar shapes. The interface-using code will (not so) intelligently determine how to map the semantic requests onto the shape of the actual object, and can do this differently based on the object provided.

from fuzzy_interfaces import fuzzy_getattr

class Car:
    def drive(self):
        print("Car.drive()")

class Bike:
    def ride(self):
        print("Bike.ride()")

def driveVehicle(vehicle):
    func = fuzzy_getattr(vehicle, "drive")
    func()

driveVehicle(Car())  # prints "Car.drive()"
driveVehicle(Bike()) # prints "Bike.ride()"